Message ID | 20231101142926.2722603-2-ben.wolsieffer@hefring.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp463107vqx; Wed, 1 Nov 2023 07:31:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEZWr/6OPYqqAaIceXebH5qKdxS5Ggw7k81ouR2rbbTby38Xj8x8XY4THKn0XEZjqoHmScL X-Received: by 2002:a05:6870:5cc6:b0:1e9:a248:b1b6 with SMTP id et6-20020a0568705cc600b001e9a248b1b6mr18674449oab.35.1698849062112; Wed, 01 Nov 2023 07:31:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698849062; cv=none; d=google.com; s=arc-20160816; b=oIVn6qRtVV75CYoCO/h6XUPdoozGNiGA8yK5d4GKC7YNVJ5P8OhZxjAw5jkx2l++eJ TMj6jn+hMHjOdPu12+hTYFbp6ewlyTKQXwQGXt57EO7IUCdyaSOOvWVVDCz16PZyuKE+ uXpBIcqJF3xf6SsSthwREeT5b0IkdkbqoCnVfEBFULKe4f3wKSMQII1QT8LbdQxsoyhB hMnVJ3oJOqT6xO/oJ/CngfYOPL5Os5eJjTlqadut8M8lo7EbP6/5uIp8rByeZbhVE8Zo QeVdVw4xIVwJ+ohXkgy9TdGppxKc9D2fBcMuFuVHCsnbYr9kk+whdMl4KUdk6AokWQgP keVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=rOY9zZGB8DVCxMyDL1I2thOcY+vKDhA+US0rF09l4kw=; fh=1rc1XUp1bKzRa92nYuSAN+4xSCYORHajs8tJsNPKYuQ=; b=sN143+BWptGK41PjB6nQSDq4HVk/cS/GEYfFwKm9jWMr4nFoAiccF8pWDsO7GC9rBt O6/AR78eKN2uAbiVF5CqBolJlBiVTF3FxqGtb2zK9QaKz/blWeJnqY4X+cwwuiL755ni OJqzkfkGn4PUAB46Qh9KpYwbBje6diw/yb1N4FjHnHR5BEAto81FY/HZvpC0auy+sxa8 tcTgKBwtcLxQiHn9H60vi4BA0oqXc9lqKIIv3ru9dLqA0ZBanjTLDAbOjxay7wE8Catj YtNQjovfK6My50Zh77pZapnbYcfduOPSLKLVxR7pRkoWVQOI6+1QwfzHlUla6PxhPyE1 TlGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b="G6Sd+dz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id s17-20020a632c11000000b005b2d044af30si3055267pgs.480.2023.11.01.07.31.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 07:31:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@hefring-com.20230601.gappssmtp.com header.s=20230601 header.b="G6Sd+dz/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4A76A807D3CF; Wed, 1 Nov 2023 07:30:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344339AbjKAOaU (ORCPT <rfc822;rbbytesnap@gmail.com> + 35 others); Wed, 1 Nov 2023 10:30:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233968AbjKAOaT (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 1 Nov 2023 10:30:19 -0400 Received: from mail-oi1-x22c.google.com (mail-oi1-x22c.google.com [IPv6:2607:f8b0:4864:20::22c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06FEDDE for <linux-kernel@vger.kernel.org>; Wed, 1 Nov 2023 07:30:14 -0700 (PDT) Received: by mail-oi1-x22c.google.com with SMTP id 5614622812f47-3b2f507c03cso3651558b6e.2 for <linux-kernel@vger.kernel.org>; Wed, 01 Nov 2023 07:30:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hefring-com.20230601.gappssmtp.com; s=20230601; t=1698849012; x=1699453812; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=rOY9zZGB8DVCxMyDL1I2thOcY+vKDhA+US0rF09l4kw=; b=G6Sd+dz/ZQVylr954A0qtLFViRQP65xD5rDFu05glJAMZ/q4OYpVDevRDtrzWj06Xq fd275cqaz911SZsp+UYWoF+m/OcmxhNseVRwyi+C+QCxcoAwazY5wggydCQbUbD9LdnH 696KcqJvT2TGhNnQcaXlvfr0CG+jWTK/OVK/9Au1BCddI5usVY9mhvup2E+J5nP/LcKF lxYUlwSyM9obdmyLkSRGS2ex38+SaDiew0z107dPpJ0aWg9QjvLLlY+KcZVYdwdJ5SF8 mliKxjxqDD5nGGXKy31k9jzPawbldu+2gNi3DGlFyWRa2GYLVzQ7xgWiHW+mwJVhyfql D9VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698849012; x=1699453812; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rOY9zZGB8DVCxMyDL1I2thOcY+vKDhA+US0rF09l4kw=; b=r7P0dgj8Wnob3pIgaiv54yIgeLBCepY6wKeTx3xN6uQ/po/uGa8rvkoAfnPagLAQ7p KKVvwcWOw6t6GRKzTvgtONmobsE3ZrViE5jIxx5DQciXM11uJ9yiUnnygsrM8zHwwSo7 MEmMYxhcR86BiQo2S0LTp6l6hN8H2SIdutobRYoWYcbZAEGliSwUhLbVagWjH83HjZAD UEdWll+1n4YSgqA6hW/lZPjuwMPRsNJfwNpdJtjuVQU5f4wfF1w5tgSAztB8odSOd7c/ z0dAGBmFoaWYe5VL/ArnBYP8wpCtLrLulP01YizYoTegYI+z1z4QaC3OG3v9+yVY8hUw kIvg== X-Gm-Message-State: AOJu0YzeFN7On/+0AtcI52Qb0lFaDuY0gXo6gGzZN233s2CKfhnECCUf Cmvs1rcmpUXvsM1Is9nNpYAIHK1ygkYT3b3wu1s= X-Received: by 2002:aca:d10:0:b0:3ae:5c09:73ce with SMTP id 16-20020aca0d10000000b003ae5c0973cemr16363378oin.23.1698849012477; Wed, 01 Nov 2023 07:30:12 -0700 (PDT) Received: from localhost.localdomain ([50.212.55.89]) by smtp.gmail.com with ESMTPSA id x11-20020a05620a14ab00b0076f058f5834sm1469260qkj.61.2023.11.01.07.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 07:30:11 -0700 (PDT) From: Ben Wolsieffer <ben.wolsieffer@hefring.com> To: linux-kernel@vger.kernel.org Cc: Mark Brown <broonie@kernel.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, "Rafael J. Wysocki" <rafael@kernel.org>, Ben Whitten <ben.whitten@gmail.com>, Ben Wolsieffer <ben.wolsieffer@hefring.com> Subject: [PATCH] regmap: prevent noinc writes from clobbering cache Date: Wed, 1 Nov 2023 10:29:27 -0400 Message-ID: <20231101142926.2722603-2-ben.wolsieffer@hefring.com> X-Mailer: git-send-email 2.42.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 01 Nov 2023 07:30:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781372353952071122 X-GMAIL-MSGID: 1781372353952071122 |
Series |
regmap: prevent noinc writes from clobbering cache
|
|
Commit Message
Ben Wolsieffer
Nov. 1, 2023, 2:29 p.m. UTC
Currently, noinc writes are cached as if they were standard incrementing
writes, overwriting unrelated register values in the cache. Instead, we
want to cache the last value written to the register, as is done in the
accelerated noinc handler (regmap_noinc_readwrite).
Fixes: cdf6b11daa77 ("regmap: Add regmap_noinc_write API")
Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com>
---
drivers/base/regmap/regmap.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
Comments
On Wed, Nov 01, 2023 at 10:29:27AM -0400, Ben Wolsieffer wrote: > Currently, noinc writes are cached as if they were standard incrementing > writes, overwriting unrelated register values in the cache. Instead, we > want to cache the last value written to the register, as is done in the > accelerated noinc handler (regmap_noinc_readwrite). Could you please add a kunit test for this?
On Wed, Nov 01, 2023 at 10:29:27AM -0400, Ben Wolsieffer wrote: > Currently, noinc writes are cached as if they were standard incrementing > writes, overwriting unrelated register values in the cache. Instead, we > want to cache the last value written to the register, as is done in the > accelerated noinc handler (regmap_noinc_readwrite). > > Fixes: cdf6b11daa77 ("regmap: Add regmap_noinc_write API") > Signed-off-by: Ben Wolsieffer <ben.wolsieffer@hefring.com> > --- > drivers/base/regmap/regmap.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > > diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c > index 234a84ecde8b..ea6157747199 100644 > --- a/drivers/base/regmap/regmap.c > +++ b/drivers/base/regmap/regmap.c > @@ -1620,17 +1620,19 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, > } > > if (!map->cache_bypass && map->format.parse_val) { > - unsigned int ival; > + unsigned int ival, offset; > int val_bytes = map->format.val_bytes; > - for (i = 0; i < val_len / val_bytes; i++) { > - ival = map->format.parse_val(val + (i * val_bytes)); > - ret = regcache_write(map, > - reg + regmap_get_offset(map, i), > - ival); > + > + /* Cache the last written value for noinc writes */ > + i = noinc ? val_len - val_bytes : 0; > + for (; i < val_len; i += val_bytes) { > + ival = map->format.parse_val(val + i); > + offset = noinc ? 0 : regmap_get_offset(map, i / val_bytes); > + ret = regcache_write(map, reg + offset, ival); > if (ret) { > dev_err(map->dev, > "Error in caching of register: %x ret: %d\n", > - reg + regmap_get_offset(map, i), ret); > + reg + offset, ret); > return ret; > } > } > -- > 2.42.0 > Hi, This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree. You are receiving this message because of the following common error(s) as indicated below: - You have marked a patch with a "Fixes:" tag for a commit that is in an older released kernel, yet you do not have a cc: stable line in the signed-off-by area at all, which means that the patch will not be applied to any older kernel releases. To properly fix this, please follow the documented rules in the Documentation/process/stable-kernel-rules.rst file for how to resolve this. If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers. thanks, greg k-h's patch email bot
Hi Mark, On Wed, Nov 01, 2023 at 05:05:39PM +0000, Mark Brown wrote: > On Wed, Nov 01, 2023 at 10:29:27AM -0400, Ben Wolsieffer wrote: > > Currently, noinc writes are cached as if they were standard incrementing > > writes, overwriting unrelated register values in the cache. Instead, we > > want to cache the last value written to the register, as is done in the > > accelerated noinc handler (regmap_noinc_readwrite). > > Could you please add a kunit test for this? I started to look into this, but it is not currently possible to test noinc behavior with regmap_[raw_]ram. The same bulk write operation is used by both incrementing and non-incrementing writes, and the difference in behavior is due to how the hardware handles the bulk write to a particular register. To test this behavior, regmap_raw_ram (raw because it supports bulk writes) would have to be told that certain of its registers should implement noinc semantics. Is this something I should implement? Thanks, Ben
On Wed, Nov 01, 2023 at 04:20:08PM -0400, Ben Wolsieffer wrote: > On Wed, Nov 01, 2023 at 05:05:39PM +0000, Mark Brown wrote: > > Could you please add a kunit test for this? > I started to look into this, but it is not currently possible to test > noinc behavior with regmap_[raw_]ram. The same bulk write operation is > used by both incrementing and non-incrementing writes, and the difference > in behavior is due to how the hardware handles the bulk write to a > particular register. > To test this behavior, regmap_raw_ram (raw because it supports bulk > writes) would have to be told that certain of its registers should > implement noinc semantics. > Is this something I should implement? That would be great, yes - I've just been implementing features in those map types on an as needed basis as I've been writing tests and I didn't get round to covering noinc yet.
On Wed, 01 Nov 2023 10:29:27 -0400, Ben Wolsieffer wrote: > Currently, noinc writes are cached as if they were standard incrementing > writes, overwriting unrelated register values in the cache. Instead, we > want to cache the last value written to the register, as is done in the > accelerated noinc handler (regmap_noinc_readwrite). > > Applied to https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regmap.git for-next Thanks! [1/1] regmap: prevent noinc writes from clobbering cache commit: 984a4afdc87a1fc226fd657b1cd8255c13d3fc1a All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark
diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index 234a84ecde8b..ea6157747199 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -1620,17 +1620,19 @@ static int _regmap_raw_write_impl(struct regmap *map, unsigned int reg, } if (!map->cache_bypass && map->format.parse_val) { - unsigned int ival; + unsigned int ival, offset; int val_bytes = map->format.val_bytes; - for (i = 0; i < val_len / val_bytes; i++) { - ival = map->format.parse_val(val + (i * val_bytes)); - ret = regcache_write(map, - reg + regmap_get_offset(map, i), - ival); + + /* Cache the last written value for noinc writes */ + i = noinc ? val_len - val_bytes : 0; + for (; i < val_len; i += val_bytes) { + ival = map->format.parse_val(val + i); + offset = noinc ? 0 : regmap_get_offset(map, i / val_bytes); + ret = regcache_write(map, reg + offset, ival); if (ret) { dev_err(map->dev, "Error in caching of register: %x ret: %d\n", - reg + regmap_get_offset(map, i), ret); + reg + offset, ret); return ret; } }