Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp325030pxb; Mon, 7 Feb 2022 12:16:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvwiV73/s3IfYxYRhUK2U6xppOSBZRzJJ/ZQnbGl+kc6B03tMUU2uswDzfn6sHootwmdB+ X-Received: by 2002:a17:907:c14:: with SMTP id ga20mr1049806ejc.243.1644264986052; Mon, 07 Feb 2022 12:16:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644264986; cv=none; d=google.com; s=arc-20160816; b=ZmbLMIWpQq1/02jNRhgAkgAK5uqya8r7ry4KU7u0K+uQxKYVwvNhzDvMvsa2e3HM/x GO3jLN328dc527UUIAcXN7l1GhmYjdZQwbUQHLE9OX3hNuLqTogUTxlRslYqj8h+nteg 1nsEVc5YMLuD5UaeiKtVcnswBXnJZQ17Sl2w2i+RDq51bEl3VHzYgzqnsJRbwlMXSc6y 9QbHGis1iO2xoow6vDGgh1GqDI3hfrIBsFRDhMHj2h3Ry5GWDo0//tXiP/r4Yw6XU/fv eVWUt/sidO+OQbA27or8O1aStNWPv8btUSVD42xtnOv5LL10eWlndFXoQS7/9EsZCnBL Rpgw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nmvrrSZBnOW9BYsZir1sD08G8R3iDOLeQdxAu+8GOh4=; b=XPpa3Tu9TtSCim/1hEJ5rXySdDAzC1AW4XCdD0qHMCe4y0DOmg6CiGDJPM+6dN/MA5 sNWlvNEGplh6+ZJWB4T4/u9eUsdh8V9QbMMslmrqC/PjZ9wELPukllgvkzqQRQONt2eT Nq+DrfGnrB99WGvM0KS2bnV7MqcRgkK2PCk/pPYMrVQvaR1k3goAUsc9FopyEDETqoLC sH5QuG9agexbx/7FUU720uz/0O7lgJKCtgnREO7S/OV+EPMo+EN2IBWQ6YPBFpNaPCxa MwpNJR0r4Z0PH4YlZ1q+FQemov/EORcbrMeMbnTaoYQah8T6bBY0c6qlWRv4xuQiNuob i1ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jrlYvKf8; 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 v1si8632979ejd.983.2022.02.07.12.16.00; Mon, 07 Feb 2022 12:16:26 -0800 (PST) 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=jrlYvKf8; 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 S1357928AbiBDJYs (ORCPT + 99 others); Fri, 4 Feb 2022 04:24:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357552AbiBDJYA (ORCPT ); Fri, 4 Feb 2022 04:24:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E968C061756; Fri, 4 Feb 2022 01:24:00 -0800 (PST) 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 ams.source.kernel.org (Postfix) with ESMTPS id 3576AB836E9; Fri, 4 Feb 2022 09:23:50 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FCE7C340ED; Fri, 4 Feb 2022 09:23:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643966629; bh=wsDPVvMJ3fihSgGDbISGT78IhKQRNro2j33j6ziBLu4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jrlYvKf8iVqxO/4Nv+xUycCoAQSst0biifWmVk8Kp+09sw06/1ljdR5jeg6+fDk0U S56/wXDVViBtmt5Mqvit4/bzD5K+T2av15yqcfPO03iIa5mKnN1+b1BxB9NyeBbrW8 qMaXJFEBbF45qjOTfbwmibOS47dkuFkA5ACIfzeA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alex Elder , "David S. Miller" Subject: [PATCH 5.15 04/32] net: ipa: prevent concurrent replenish Date: Fri, 4 Feb 2022 10:22:14 +0100 Message-Id: <20220204091915.389958277@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220204091915.247906930@linuxfoundation.org> References: <20220204091915.247906930@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alex Elder commit 998c0bd2b3715244da7639cc4e6a2062cb79c3f4 upstream. We have seen cases where an endpoint RX completion interrupt arrives while replenishing for the endpoint is underway. This causes another instance of replenishing to begin as part of completing the receive transaction. If this occurs it can lead to transaction corruption. Use a new flag to ensure only one replenish instance for an endpoint executes at a time. Fixes: 84f9bd12d46db ("soc: qcom: ipa: IPA endpoints") Signed-off-by: Alex Elder Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- drivers/net/ipa/ipa_endpoint.c | 13 +++++++++++++ drivers/net/ipa/ipa_endpoint.h | 2 ++ 2 files changed, 15 insertions(+) --- a/drivers/net/ipa/ipa_endpoint.c +++ b/drivers/net/ipa/ipa_endpoint.c @@ -1075,15 +1075,27 @@ static void ipa_endpoint_replenish(struc return; } + /* If already active, just update the backlog */ + if (test_and_set_bit(IPA_REPLENISH_ACTIVE, endpoint->replenish_flags)) { + if (add_one) + atomic_inc(&endpoint->replenish_backlog); + return; + } + while (atomic_dec_not_zero(&endpoint->replenish_backlog)) if (ipa_endpoint_replenish_one(endpoint)) goto try_again_later; + + clear_bit(IPA_REPLENISH_ACTIVE, endpoint->replenish_flags); + if (add_one) atomic_inc(&endpoint->replenish_backlog); return; try_again_later: + clear_bit(IPA_REPLENISH_ACTIVE, endpoint->replenish_flags); + /* The last one didn't succeed, so fix the backlog */ delta = add_one ? 2 : 1; backlog = atomic_add_return(delta, &endpoint->replenish_backlog); @@ -1666,6 +1678,7 @@ static void ipa_endpoint_setup_one(struc * backlog is the same as the maximum outstanding TREs. */ clear_bit(IPA_REPLENISH_ENABLED, endpoint->replenish_flags); + clear_bit(IPA_REPLENISH_ACTIVE, endpoint->replenish_flags); atomic_set(&endpoint->replenish_saved, gsi_channel_tre_max(gsi, endpoint->channel_id)); atomic_set(&endpoint->replenish_backlog, 0); --- a/drivers/net/ipa/ipa_endpoint.h +++ b/drivers/net/ipa/ipa_endpoint.h @@ -44,10 +44,12 @@ enum ipa_endpoint_name { * enum ipa_replenish_flag: RX buffer replenish flags * * @IPA_REPLENISH_ENABLED: Whether receive buffer replenishing is enabled + * @IPA_REPLENISH_ACTIVE: Whether replenishing is underway * @IPA_REPLENISH_COUNT: Number of defined replenish flags */ enum ipa_replenish_flag { IPA_REPLENISH_ENABLED, + IPA_REPLENISH_ACTIVE, IPA_REPLENISH_COUNT, /* Number of flags (must be last) */ };