From patchwork Thu Jun 1 10:10:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 101866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp201139vqr; Thu, 1 Jun 2023 03:32:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4nEzDMVF0hyPS0xZtHZ1dyeoRRi3wrpu/ewgxbInvmHdEEMl914QXViEKrrPFgdaMhPu8E X-Received: by 2002:a05:6808:1496:b0:398:36a0:d0c with SMTP id e22-20020a056808149600b0039836a00d0cmr8261293oiw.33.1685615527193; Thu, 01 Jun 2023 03:32:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685615527; cv=none; d=google.com; s=arc-20160816; b=xcQrl3mz07HbS/QhRfCP+Ux2RbsFSkAHbDNsyiIOH/3kb6PR8LeuBzmEHeyY6C/9g+ LAilXBuVBHqCQrfvGUz9BiPvuXzu0491MxT9Shpf23GSux/quhcssq0lTW7tOx2xLnXV Wm5Gc4dshL11+tuScYTLaOzrUUrniB3Ev3v7/8sALemj4IBQSo52Z7Q5oeqU3c3QAMhz USQorbT7aiI9bmwtIcSaZ9ejtnnycb1GIKowCKKOtlvRX58tnEKFF/Bh5CzGZYdfTwS5 LjvmLSfUbsBmep1lkZVmMTyEiswajTyVB9v8ODIQ4A2Zs/UZRDuwrymtREkRXBadZhLE Ke+Q== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CYjUlUokqgwvfm/eWCGzun35GxlTrPgpDxWqqtsJt6s=; b=03vqTsz9KjF+HaO7hXcDeqOEtjeO59gvBcQ9uIb1W2/9oRjjkHyIdOw1y8tkoAvGTR 07FA0FE+BQtiR20aSKLfru2JKR3WDQVMwLCKkXn7SwroAx0zNQRkfBz4CQ0d93ZYoR6e asJCy8GpaZ182BB8pC6nUJC//OHJAQfYcdAHzpMON5qaFlRhkwnRNI6+tiON2H0as5Q4 ISup7488dycwlEOcpBErUIMGoma3tsSoAYyhyGwq+I8vX3w4qax4mS1gINc48MplxoBl /AH9ggAAmTdSfs8pMKQDsnvzqke322JhXwvmYC7U39RfuddCnlefi0suHypH5hpWcdVa 5LoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b="GgoEvh/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r1-20020aa79621000000b0064d2e108cecsi3792338pfg.104.2023.06.01.03.31.53; Thu, 01 Jun 2023 03:32:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cirrus.com header.s=PODMain02222019 header.b="GgoEvh/w"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233189AbjFAKMm (ORCPT + 99 others); Thu, 1 Jun 2023 06:12:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233350AbjFAKLe (ORCPT ); Thu, 1 Jun 2023 06:11:34 -0400 Received: from mx0b-001ae601.pphosted.com (mx0a-001ae601.pphosted.com [67.231.149.25]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2372E49 for ; Thu, 1 Jun 2023 03:10:49 -0700 (PDT) Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 3515qxEA012309; Thu, 1 Jun 2023 05:10:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cirrus.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=PODMain02222019; bh=CYjUlUokqgwvfm/eWCGzun35GxlTrPgpDxWqqtsJt6s=; b=GgoEvh/wmZtSEQZhKxSaZL2ozjG1nRLbK9GW52YTtWXC5mHYD4XVu8xPYaEM3NRPyAn7 T7oDYvu8F6Z7IJjc7EBRoxZPoAth0ORCP7KoLDkQFu/cHjMba8eZxkyPiyLFjL8hKyNL bVNhv937OSmAlvA4seZJyJd0VOYlFtUGPQBYrEwvRF0Y36RmYGBeLZydpXm4zbEGEcQF YUH9NO3xQvx5VfMPG0cEB0X83yd7jl55ZiKNoqH88gbWp/MOM5xButF1blKkLsaVhVci Zo1Chnd8c6W7ox2sFaeDdEdvexWze03vVJNspI1pXaJb5IYdQ5zaLOmb3ATHM/HcR4GG zA== Received: from ediex01.ad.cirrus.com ([84.19.233.68]) by mx0a-001ae601.pphosted.com (PPS) with ESMTPS id 3quf90wqub-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Jun 2023 05:10:46 -0500 Received: from ediex02.ad.cirrus.com (198.61.84.81) by ediex01.ad.cirrus.com (198.61.84.80) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.26; Thu, 1 Jun 2023 11:10:36 +0100 Received: from ediswmail.ad.cirrus.com (198.61.86.93) by anon-ediex02.ad.cirrus.com (198.61.84.81) with Microsoft SMTP Server id 15.2.1118.26 via Frontend Transport; Thu, 1 Jun 2023 11:10:36 +0100 Received: from algalon.ad.cirrus.com (algalon.ad.cirrus.com [198.90.251.122]) by ediswmail.ad.cirrus.com (Postfix) with ESMTP id 2119C475; Thu, 1 Jun 2023 10:10:36 +0000 (UTC) From: Charles Keepax To: CC: , , , Subject: [PATCH 2/2] regmap: Add missing cache_only checks Date: Thu, 1 Jun 2023 11:10:36 +0100 Message-ID: <20230601101036.1499612-2-ckeepax@opensource.cirrus.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230601101036.1499612-1-ckeepax@opensource.cirrus.com> References: <20230601101036.1499612-1-ckeepax@opensource.cirrus.com> MIME-Version: 1.0 X-Proofpoint-GUID: Liq_mNh9AWkq98Wsc3QFSaKV-UhO6GYd X-Proofpoint-ORIG-GUID: Liq_mNh9AWkq98Wsc3QFSaKV-UhO6GYd X-Proofpoint-Spam-Reason: safe X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767495987031482605?= X-GMAIL-MSGID: =?utf-8?q?1767495987031482605?= The current behaviour around cache_only is slightly inconsistent, most paths will only check cache_only if cache_bypass is false, and will return -EBUSY if a read attempts to go to the hardware whilst cache_only is true. However, a couple of paths will not check cache_only at all. The most notable of these being regmap_raw_read which will check cache_only in the case it processes the transaction one register at a time, but not in the case it handles them as a block. In the typical case a device has been put into cache_only whilst powered down this can cause physical reads to happen whilst the device is unavailable. Add a check in regmap_raw_read and move the check in regmap_noinc_read, adding a check for cache_bypass, such that all paths are covered and consistent. Signed-off-by: Charles Keepax --- drivers/base/regmap/regmap.c | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c index fa2d3fba6ac9d..627a767fa0470 100644 --- a/drivers/base/regmap/regmap.c +++ b/drivers/base/regmap/regmap.c @@ -2983,6 +2983,11 @@ int regmap_raw_read(struct regmap *map, unsigned int reg, void *val, size_t chunk_count, chunk_bytes; size_t chunk_regs = val_count; + if (!map->cache_bypass && map->cache_only) { + ret = -EBUSY; + goto out; + } + if (!map->read) { ret = -ENOTSUPP; goto out; @@ -3078,18 +3083,19 @@ int regmap_noinc_read(struct regmap *map, unsigned int reg, goto out_unlock; } + /* + * We have not defined the FIFO semantics for cache, as the + * cache is just one value deep. Should we return the last + * written value? Just avoid this by always reading the FIFO + * even when using cache. Cache only will not work. + */ + if (!map->cache_bypass && map->cache_only) { + ret = -EBUSY; + goto out_unlock; + } + /* Use the accelerated operation if we can */ if (map->bus->reg_noinc_read) { - /* - * We have not defined the FIFO semantics for cache, as the - * cache is just one value deep. Should we return the last - * written value? Just avoid this by always reading the FIFO - * even when using cache. Cache only will not work. - */ - if (map->cache_only) { - ret = -EBUSY; - goto out_unlock; - } ret = regmap_noinc_readwrite(map, reg, val, val_len, false); goto out_unlock; }