Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp5147495rwe; Tue, 18 Apr 2023 02:46:37 -0700 (PDT) X-Google-Smtp-Source: AKy350bVYEhmE+vn8qnGEhurT5b1OOiDE1zTh9Rlxe+FAdR9ae3iy2h7K11ATOqHXcGLabbomXlc X-Received: by 2002:a05:6a00:88e:b0:626:2ae6:31f6 with SMTP id q14-20020a056a00088e00b006262ae631f6mr26790029pfj.7.1681811196677; Tue, 18 Apr 2023 02:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681811196; cv=none; d=google.com; s=arc-20160816; b=iA2X4lYnxWGPvkTW0NMUVAhZUC2GWj+G0q0re3Z0tjRjqM3nyXXQv1JbvB8NiyTao9 LoOTTYJFNnJLNxSXpRvimpnPbQR5Kuzsx/ejdNhGJVOYEaC5ANz70VUiMUAwwA1et7ba n5Lim4kUy5X3yKasRw2vAmpCAFQZ8Nzn3RAqyfiyYa2B4VB3pcZXO+RykqMd+975KmYN hf03mOMyVMUhMRcM6O9Exw6kPZwYFujv1ZUTdA8vhsoyU68NiD+kTA+XFCSvjJnY8HDA GtKVrO3hSABGl+HjdqHGu5tO0Gf2WZyA9LSDEtRBfprbzrAKiNGL+gjFKCH2g0IX3NV0 mCVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=sRmqHdZZgxs545d+ZqPixiTw5++Unjbeibd+ExHL2h8=; b=0qZ2y+gEKms9+c3CKM16MgBNk69kW1rPRjYD0crriPj1aHPko8nIeJ0agxWY+k3Eeu SzN6A32+7cKJJCt9XniETllE0dXnoZlyT2AuEIy6x6xoNWW/JG9GMwJuZ+KsjtQVAuc7 O9iScd1v+U+i41lKhTrfRgKQG55Nt1tRWrz0yP/X104D8J11w7Z3nvtHMWW2a7I05yiN xJVQLL/bL1pLljONGsr8PtyxrTkaPj7r/WSoz8gF7oG+emHgX/kCOsPHSOP6TWpErJtP UzTsK3s7Iq8sBDNwn465J4CpNu9bJWyic0Edt7HWKsf0i1GNawtQsFG32oKWtKbhwJiO kiFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=InrJp0SH; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s17-20020a63ff51000000b0051322a8d2aesi13504073pgk.110.2023.04.18.02.46.23; Tue, 18 Apr 2023 02:46:36 -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=@linuxfoundation.org header.s=korg header.b=InrJp0SH; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230440AbjDRJmA (ORCPT + 99 others); Tue, 18 Apr 2023 05:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231407AbjDRJlf (ORCPT ); Tue, 18 Apr 2023 05:41:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07D9A76A2; Tue, 18 Apr 2023 02:41:33 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7582662CFB; Tue, 18 Apr 2023 09:41:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F5D4C433EF; Tue, 18 Apr 2023 09:41:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1681810891; bh=T7+yT2pUreBDqbXZDE2c2Eq03kSJu9kHFQ2uyasQtNo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=InrJp0SHl8sfq+QUs8insdG7q7IbfNCEmtZJKl7pc3+S+sZjQ1BBgoA9AyS498MHe l2xzrQwYkI/kxslAewBsLUY42ICSvTvD5+hRwlbNxlp+wGRTuLb3dt8PeDd/Pzo1Zs ich6Z15IXvvY3G5TBtFL4uSeRC5m4yhKqydY/GQM= Date: Tue, 18 Apr 2023 11:41:29 +0200 From: Greg Kroah-Hartman To: William Breathitt Gray Cc: linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , stable@vger.kernel.org Subject: Re: [RESEND PATCH 5.15 v3 5/5] counter: 104-quad-8: Fix race condition between FLAG and CNTR reads Message-ID: <2023041849-nursing-cling-8729@gregkh> References: <20230411155220.9754-1-william.gray@linaro.org> <20230411155220.9754-5-william.gray@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 On Mon, Apr 17, 2023 at 09:40:52AM -0400, William Breathitt Gray wrote: > On Tue, Apr 11, 2023 at 11:52:20AM -0400, William Breathitt Gray wrote: > > commit 4aa3b75c74603c3374877d5fd18ad9cc3a9a62ed upstream. > > > > The Counter (CNTR) register is 24 bits wide, but we can have an > > effective 25-bit count value by setting bit 24 to the XOR of the Borrow > > flag and Carry flag. The flags can be read from the FLAG register, but a > > race condition exists: the Borrow flag and Carry flag are instantaneous > > and could change by the time the count value is read from the CNTR > > register. > > > > Since the race condition could result in an incorrect 25-bit count > > value, remove support for 25-bit count values from this driver. > > > > Fixes: 28e5d3bb0325 ("iio: 104-quad-8: Add IIO support for the ACCES 104-QUAD-8") > > Cc: # 5.15.x > > Signed-off-by: William Breathitt Gray > > --- > > drivers/counter/104-quad-8.c | 18 +++--------------- > > 1 file changed, 3 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/counter/104-quad-8.c b/drivers/counter/104-quad-8.c > > index 0caa60537b..643aae0c9f 100644 > > --- a/drivers/counter/104-quad-8.c > > +++ b/drivers/counter/104-quad-8.c > > @@ -61,10 +61,6 @@ struct quad8 { > > #define QUAD8_REG_CHAN_OP 0x11 > > #define QUAD8_REG_INDEX_INPUT_LEVELS 0x16 > > #define QUAD8_DIFF_ENCODER_CABLE_STATUS 0x17 > > -/* Borrow Toggle flip-flop */ > > -#define QUAD8_FLAG_BT BIT(0) > > -/* Carry Toggle flip-flop */ > > -#define QUAD8_FLAG_CT BIT(1) > > /* Error flag */ > > #define QUAD8_FLAG_E BIT(4) > > /* Up/Down flag */ > > @@ -121,17 +117,9 @@ static int quad8_count_read(struct counter_device *counter, > > { > > struct quad8 *const priv = counter->priv; > > const int base_offset = priv->base + 2 * count->id; > > - unsigned int flags; > > - unsigned int borrow; > > - unsigned int carry; > > int i; > > > > - flags = inb(base_offset + 1); > > - borrow = flags & QUAD8_FLAG_BT; > > - carry = !!(flags & QUAD8_FLAG_CT); > > - > > - /* Borrow XOR Carry effectively doubles count range */ > > - *val = (unsigned long)(borrow ^ carry) << 24; > > + *val = 0; > > > > mutex_lock(&priv->lock); > > > > @@ -699,8 +687,8 @@ static ssize_t quad8_count_ceiling_read(struct counter_device *counter, > > > > mutex_unlock(&priv->lock); > > > > - /* By default 0x1FFFFFF (25 bits unsigned) is maximum count */ > > - return sprintf(buf, "33554431\n"); > > + /* By default 0xFFFFFF (24 bits unsigned) is maximum count */ > > + return sprintf(buf, "16777215\n"); > > } > > > > static ssize_t quad8_count_ceiling_write(struct counter_device *counter, > > > > base-commit: d86dfc4d95cd218246b10ca7adf22c8626547599 > > -- > > 2.39.2 > > Greg, > > This patch will no longer apply to 5.15.x when the "counter: Internalize > sysfs interface code" patch in the stable-queue tree is merged [0]. > However, I believe the 6.1 backport [1] will apply instead at that > point. What is the best way to handle this situation? Should I resend > the 6.1 backport with the stable list Cc tag adjusted for 5.15.x, or are > you able to apply the 6.1 backport patch directly to the 5.15.x tree? The 6.1.y backport didn't apply either :( Can you resend all of these rebased against the next round of stable releases when they are released later this week? thanks, greg k-h