From nobody Mon Apr 6 20:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DB098C6FA89 for ; Fri, 2 Sep 2022 21:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbiIBVCd (ORCPT ); Fri, 2 Sep 2022 17:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230458AbiIBVC0 (ORCPT ); Fri, 2 Sep 2022 17:02:26 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 054BDB2CFF for ; Fri, 2 Sep 2022 14:02:24 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id r141so2659996iod.4 for ; Fri, 02 Sep 2022 14:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=CapqBxxG2aQ7YyEDkhNervwPkhRRBUyf1g0dzj7goM4=; b=eYvg4J5jpvvPaQIqJUqSlwN0mHZaEJbWRNbtYkVhnkl+auAHZJm668yx5tVKTAcoAW x2x7jfh0NmBDsRGusvSwypORs2PY5dsaIlcYOF59ojoo/jL63B2G2nMWNjAjcwrTNojY NwOgSJldMVyvo/tkvGi5be241KJiL5/XYygVOlKcGDO4IQppVx0FZW/mdVsN3VV6OAtJ hBbq2fFciLD12D0RnW/LvsaHnK0TBtmRg8NiYrPERewQQNMrDjQY0zYqkAaPj7Jt5N1H ATYx5Iqo6OsagIifZ7u06HwMIVYUQFAIMmWsBHqQeE0Z/7R+gmjL3O6sFeX/dwcdESe8 jOlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=CapqBxxG2aQ7YyEDkhNervwPkhRRBUyf1g0dzj7goM4=; b=saHqa1smjHlbFcSezOPkLhdsfteLXxm5VLpsc5I0lvD+z5w7qcgsDkHU+kO98zoAwV Oxs8w76R3E+bZYgCE1NqhMvHxpcCpy4Lte0porJ14DwuSuP0BfY11WvURoN8nU4c4qN0 MJ2uia56/XMC/1yCIuswHN0YJTDHbXHYaSp0ja9G9LKBrlibjef04FGumLPCmT+1uJ/S szISTA74nYpHTRkYWWYNjVKJJCoN8fKcRP+v4AGl0pSrEZMRJMMbPq86NWv2nJSNMbjP MzaFZf4ygg1p4ToilnkcXI47eNrKCW1kX/8oaDPbZ0SG26oB9791Rv+gGpmFNTfhbxV3 lniA== X-Gm-Message-State: ACgBeo3TBw731Y8y5gUnNasbcLXPrmzkBMS9IDxYzLU8EauLagJXw69m lDYCYmGd36AgIH6sJDV87rUw7g== X-Google-Smtp-Source: AA6agR7Gnx2ZG9dvb0e7jrJUIVtwH7AObQFpx6Y8qeynDsUXuODKsVVGmdwdmgXxxgNSEvDMdh8Q/Q== X-Received: by 2002:a05:6638:2042:b0:34c:f22:25b3 with SMTP id t2-20020a056638204200b0034c0f2225b3mr7240077jaj.75.1662152543043; Fri, 02 Sep 2022 14:02:23 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id i7-20020a0566022c8700b00689e718d971sm1259208iow.51.2022.09.02.14.02.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 14:02:22 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/6] net: ipa: rework last transaction determination Date: Fri, 2 Sep 2022 16:02:13 -0500 Message-Id: <20220902210218.745873-2-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902210218.745873-1-elder@linaro.org> References: <20220902210218.745873-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When quiescing a channel, we find the "last" transaction, which is the latest one to have been allocated. (New transaction allocation will have been prevented by the time this is called.) Currently we do this by looking for the first non-empty transaction list in each state, then return the last entry from that last. Instead, determine the last entry in each list (if any) and return that entry if found. Temporarily (locally) introduce list_last_entry_or_null() as a helper for this, mirroring list_first_entry_or_null(). This macro definition will be removed by an upcoming patch. Remove the temporary warnings added by the previous commit. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.c | 28 ++++++++++++++-------------- drivers/net/ipa/gsi_private.h | 14 ++++++++++++++ drivers/net/ipa/gsi_trans.c | 22 ---------------------- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 9e307eebd33f9..0ea98fa5dee56 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -710,7 +710,6 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32 e= vt_ring_id) static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channe= l) { struct gsi_trans_info *trans_info =3D &channel->trans_info; - const struct list_head *list; struct gsi_trans *trans; =20 spin_lock_bh(&trans_info->spinlock); @@ -719,29 +718,30 @@ static struct gsi_trans *gsi_channel_trans_last(struc= t gsi_channel *channel) * before we disabled transmits, so check for that. */ if (channel->toward_ipa) { - list =3D &trans_info->alloc; - if (!list_empty(list)) + trans =3D list_last_entry_or_null(&trans_info->alloc, + struct gsi_trans, links); + if (trans) goto done; - list =3D &trans_info->committed; - if (!list_empty(list)) + trans =3D list_last_entry_or_null(&trans_info->committed, + struct gsi_trans, links); + if (trans) goto done; - list =3D &trans_info->pending; - if (!list_empty(list)) + trans =3D list_last_entry_or_null(&trans_info->pending, + struct gsi_trans, links); + if (trans) goto done; } =20 /* Otherwise (TX or RX) we want to wait for anything that * has completed, or has been polled but not released yet. */ - list =3D &trans_info->complete; - if (!list_empty(list)) + trans =3D list_last_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + if (trans) goto done; - list =3D &trans_info->polled; - if (list_empty(list)) - list =3D NULL; + trans =3D list_last_entry_or_null(&trans_info->polled, + struct gsi_trans, links); done: - trans =3D list ? list_last_entry(list, struct gsi_trans, links) : NULL; - /* Caller will wait for this, so take a reference */ if (trans) refcount_inc(&trans->refcount); diff --git a/drivers/net/ipa/gsi_private.h b/drivers/net/ipa/gsi_private.h index 0b2516fa21b5d..51bbc7a40dc2d 100644 --- a/drivers/net/ipa/gsi_private.h +++ b/drivers/net/ipa/gsi_private.h @@ -16,6 +16,20 @@ struct gsi_channel; =20 #define GSI_RING_ELEMENT_SIZE 16 /* bytes; must be a power of 2 */ =20 +/** + * list_last_entry_or_null - get the last element from a list + * @ptr: the list head to take the element from. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_head within the struct. + * + * Note that if the list is empty, it returns NULL. + */ +#define list_last_entry_or_null(ptr, type, member) ({ \ + struct list_head *head__ =3D (ptr); \ + struct list_head *pos__ =3D READ_ONCE(head__->prev); \ + pos__ !=3D head__ ? list_entry(pos__, type, member) : NULL; \ +}) + /** * gsi_trans_move_complete() - Mark a GSI transaction completed * @trans: Transaction to commit diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index 4eef1480c2005..b4a6f2b563566 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -309,23 +309,15 @@ void gsi_trans_move_polled(struct gsi_trans *trans) { struct gsi_channel *channel =3D &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info =3D &channel->trans_info; - u16 trans_index; =20 spin_lock_bh(&trans_info->spinlock); =20 list_move_tail(&trans->links, &trans_info->polled); =20 - trans =3D list_first_entry(&trans_info->polled, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); =20 /* This completed transaction is now polled */ trans_info->completed_id++; - - WARN_ON(trans_info->polled_id =3D=3D trans_info->completed_id); - trans_index =3D trans_info->polled_id % channel->tre_count; - WARN_ON(trans !=3D &trans_info->trans[trans_index]); } =20 /* Reserve some number of TREs on a channel. Returns true if successful */ @@ -413,11 +405,8 @@ struct gsi_trans *gsi_channel_trans_alloc(struct gsi *= gsi, u32 channel_id, /* Free a previously-allocated transaction */ void gsi_trans_free(struct gsi_trans *trans) { - struct gsi_channel *channel =3D &trans->gsi->channel[trans->channel_id]; refcount_t *refcount =3D &trans->refcount; struct gsi_trans_info *trans_info; - struct gsi_trans *polled; - u16 trans_index; bool last; =20 /* We must hold the lock to release the last reference */ @@ -433,9 +422,6 @@ void gsi_trans_free(struct gsi_trans *trans) if (last) list_del(&trans->links); =20 - polled =3D list_first_entry_or_null(&trans_info->polled, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); =20 if (!last) @@ -456,14 +442,6 @@ void gsi_trans_free(struct gsi_trans *trans) /* This transaction is now free */ trans_info->polled_id++; =20 - if (polled) { - trans_index =3D trans_info->polled_id % channel->tre_count; - WARN_ON(polled !=3D &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->polled_id !=3D - trans_info->completed_id); - } - /* Releasing the reserved TREs implicitly frees the sgl[] and * (if present) info[] arrays, plus the transaction itself. */ --=20 2.34.1 From nobody Mon Apr 6 20:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69B2EC6FA83 for ; Fri, 2 Sep 2022 21:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229681AbiIBVCg (ORCPT ); Fri, 2 Sep 2022 17:02:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35052 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230460AbiIBVC0 (ORCPT ); Fri, 2 Sep 2022 17:02:26 -0400 Received: from mail-io1-xd29.google.com (mail-io1-xd29.google.com [IPv6:2607:f8b0:4864:20::d29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B37EAB4E84 for ; Fri, 2 Sep 2022 14:02:24 -0700 (PDT) Received: by mail-io1-xd29.google.com with SMTP id p187so2635659iod.8 for ; Fri, 02 Sep 2022 14:02:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Hl3DE3DGBmmIurt4RnwSIbwXbwcvmQfsOkHdcjb4ehA=; b=nIFAP19qCeoYKPNI7pbOjx3eI6VLjPRIQwMe1yCLxXwR/qvklSstwH5D2RrS3K1ekL B/nFskNKtZLOfjx6Ro5SJnDLg2SkF2Doao6PZd/B+8hvr1pS/HzhdNKG40sWUA/Ymaq8 boBbWsnHZ9VEPqeVngwQ1Ac5bg5ixgmE0TexIIcZl+5/ZUL2cxgMMCBGs+OTpYpobd0L 1ZPKkKlNoS/zVoFNSMoYC2QKgXc8gWAIuYlS5kpslpk2sYKjm6lyJJv53fP5xd4LoSt4 GvGMGxG0Gu/qeG6UcU/LWRGVIYRcCcz5VTCk/NIiuc5KMbc/lkPQOfZpwJ7+ThXabsjN B1Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Hl3DE3DGBmmIurt4RnwSIbwXbwcvmQfsOkHdcjb4ehA=; b=z2dZnT9BfBQa9LTbMPckbCkPbq14SidxUo84NNO+pq9NvmiHuEVsIr2MGTyo8PpOfd 7oFrHCKiKl0qIFDks2+VdolXNrQ1nYoo/nG5D1b9cgBZeCPmMUmOeqKPbj8JanTolMBC 9fPwZR7eeAoPF8bkn0rVzRUVTzffn212lL4ljKHNN+qR5yq612N725OKlpWGoe9RKt63 iidzVHDcaGihm9NzAk97hhTREf9HlSn9cAJ3i61cEyDQ+XMqTA4+CXOb3qrLj0aq8dsZ YWVAG1nzaTg5dKetGx/zAFEXUUdE1l0e6RGVRRly5M881JWT9vh1N+1u99bagt0bZYvI oJ0A== X-Gm-Message-State: ACgBeo1WpgBxcFxBsU18Ezj5VCPG/H8kMXa6qbG1vfN6sf5w6rZWWpTx GvEEV49Qc8wx1TWoTG+pdpzxew== X-Google-Smtp-Source: AA6agR4QdOByxczM9RKD1gLXTWthZsvFuwAYY1NtHLAzxExT6iLpugn99qjPLbhyJwTHBKHQP4LA3g== X-Received: by 2002:a6b:5d01:0:b0:688:ac7c:95ec with SMTP id r1-20020a6b5d01000000b00688ac7c95ecmr18308999iob.142.1662152544086; Fri, 02 Sep 2022 14:02:24 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id i7-20020a0566022c8700b00689e718d971sm1259208iow.51.2022.09.02.14.02.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 14:02:23 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/6] net: ipa: use IDs for last allocated transaction Date: Fri, 2 Sep 2022 16:02:14 -0500 Message-Id: <20220902210218.745873-3-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902210218.745873-1-elder@linaro.org> References: <20220902210218.745873-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Use the allocated and free transaction IDs to determine whether the "last" transaction used for quiescing a channel is in allocated state. The last allocated transaction that has not been committed (if any) immediately precedes the first free transaction in the transaction array. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 0ea98fa5dee56..135e51980d793 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -711,6 +711,8 @@ static struct gsi_trans *gsi_channel_trans_last(struct = gsi_channel *channel) { struct gsi_trans_info *trans_info =3D &channel->trans_info; struct gsi_trans *trans; + u16 trans_index; + u16 trans_id; =20 spin_lock_bh(&trans_info->spinlock); =20 @@ -718,10 +720,14 @@ static struct gsi_trans *gsi_channel_trans_last(struc= t gsi_channel *channel) * before we disabled transmits, so check for that. */ if (channel->toward_ipa) { - trans =3D list_last_entry_or_null(&trans_info->alloc, - struct gsi_trans, links); - if (trans) + /* The last allocated transaction precedes the first free */ + if (trans_info->allocated_id !=3D trans_info->free_id) { + trans_id =3D trans_info->free_id - 1; + trans_index =3D trans_id % channel->tre_count; + trans =3D &trans_info->trans[trans_index]; goto done; + } + trans =3D list_last_entry_or_null(&trans_info->committed, struct gsi_trans, links); if (trans) --=20 2.34.1 From nobody Mon Apr 6 20:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ED1B2C6FA82 for ; Fri, 2 Sep 2022 21:02:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229962AbiIBVCm (ORCPT ); Fri, 2 Sep 2022 17:02:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35066 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230463AbiIBVC0 (ORCPT ); Fri, 2 Sep 2022 17:02:26 -0400 Received: from mail-io1-xd33.google.com (mail-io1-xd33.google.com [IPv6:2607:f8b0:4864:20::d33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8FDD266F for ; Fri, 2 Sep 2022 14:02:25 -0700 (PDT) Received: by mail-io1-xd33.google.com with SMTP id i77so2639215ioa.7 for ; Fri, 02 Sep 2022 14:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=jw3usGZHwB7uL2kMRS8aZbuB6wC7nfp91WF72vctvXA=; b=pUIZ44+Vfp8hE1PdqhEqNHazsPJPGPN8uOffVif6e3FHXbgg4VT9ySgFV2JyzY+RcN sKbDltAGT7Y1Epr0Hm2lBof04pprbdPymdkocC/1M0NN3FyKyD9E7EpNKkjBHGe/clw2 GVATAoPMTSteF9inOIXTA1mXiENXBjFtmC6WfIYQNQFyunoL+ytiivPMPtkIRik7OqnA Ydcm6byeFMJgSrjoHqW7HAAv7LxBFXN/wCyrx/jVCDEsMbZvph3UTgaeRcrpGgiA+yPE fB6JfRVreyqmS2e+Ou9+sQeh2xyfo14+YHt5h0MraxGCOCXONMtG8HAVcrfAQfs7ZNVS Om1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=jw3usGZHwB7uL2kMRS8aZbuB6wC7nfp91WF72vctvXA=; b=ZpYT74B2dNxX8jk/YqEk7EfLp5lEHIT9CUJ1H199DHa2TvNJTy/k1TcdtdW+bf3Vd7 VYDnuoCdsWaYTNiRuNxtXSpC3ZIlJ44d8Vv/BP4E1CZhf06ghcr99D3Y4i3s/7Rgty5D 1TiJKUYYTtpfjEby4/oaDbI2a9ViJeIF8VwFvJkzCGaT/liR1aSbCEnEkPvPsjy1+Bb6 z9P/ezsvJcAEuxe5pTQ50RdLuSqGGj3ed22talKG7KpxXalMscMPv9FORyMyw974AoOv kx0HtwgAKaqWErTq+nxrXlK0mtM2t5VmPvTEogXNXhaFdjvFq2YVsVCqd3Z0Nh53+Rg6 pYFQ== X-Gm-Message-State: ACgBeo0Z8kTdSiJG5i7Q7XjvqA+J8H6VgDqBV0mR5ETAceK8gyyZWRGb Oe/+ApkQwSlFYNNX9IdPgGZFJg== X-Google-Smtp-Source: AA6agR56sEYtb+xFIJK9ZN3slkJslKVczqNlXp8oZ6J9kYrILNPIc3WJA+BjTGXmuRlwDR/DdhuxwQ== X-Received: by 2002:a05:6638:488a:b0:342:6d75:dfa6 with SMTP id ct10-20020a056638488a00b003426d75dfa6mr19147130jab.319.1662152545368; Fri, 02 Sep 2022 14:02:25 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id i7-20020a0566022c8700b00689e718d971sm1259208iow.51.2022.09.02.14.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 14:02:24 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/6] net: ipa: use IDs exclusively for last transaction Date: Fri, 2 Sep 2022 16:02:15 -0500 Message-Id: <20220902210218.745873-4-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902210218.745873-1-elder@linaro.org> References: <20220902210218.745873-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Always use transaction IDs when finding the "last" transaction to await when quiescing a channel. This basically extends what was done in the previous patch to all other transaction state IDs. As a result we are no longer updating any transaction lists inside gsi_channel_trans_last(), so there's no need to take the spinlock. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 135e51980d793..0983a11409f2d 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -714,8 +714,6 @@ static struct gsi_trans *gsi_channel_trans_last(struct = gsi_channel *channel) u16 trans_index; u16 trans_id; =20 - spin_lock_bh(&trans_info->spinlock); - /* There is a small chance a TX transaction got allocated just * before we disabled transmits, so check for that. */ @@ -728,32 +726,46 @@ static struct gsi_trans *gsi_channel_trans_last(struc= t gsi_channel *channel) goto done; } =20 - trans =3D list_last_entry_or_null(&trans_info->committed, - struct gsi_trans, links); - if (trans) + /* Last committed transaction precedes the first allocated */ + if (trans_info->committed_id !=3D trans_info->allocated_id) { + trans_id =3D trans_info->allocated_id - 1; + trans_index =3D trans_id % channel->tre_count; + trans =3D &trans_info->trans[trans_index]; goto done; - trans =3D list_last_entry_or_null(&trans_info->pending, - struct gsi_trans, links); - if (trans) + } + + /* Last pending transaction precedes the first committed */ + if (trans_info->pending_id !=3D trans_info->committed_id) { + trans_id =3D trans_info->committed_id - 1; + trans_index =3D trans_id % channel->tre_count; + trans =3D &trans_info->trans[trans_index]; goto done; + } } =20 /* Otherwise (TX or RX) we want to wait for anything that * has completed, or has been polled but not released yet. + * + * The last pending transaction precedes the first committed. */ - trans =3D list_last_entry_or_null(&trans_info->complete, - struct gsi_trans, links); - if (trans) + if (trans_info->completed_id !=3D trans_info->pending_id) { + trans_id =3D trans_info->pending_id - 1; + trans_index =3D trans_id % channel->tre_count; + trans =3D &trans_info->trans[trans_index]; goto done; - trans =3D list_last_entry_or_null(&trans_info->polled, - struct gsi_trans, links); + } + if (trans_info->polled_id !=3D trans_info->completed_id) { + trans_id =3D trans_info->completed_id - 1; + trans_index =3D trans_id % channel->tre_count; + trans =3D &trans_info->trans[trans_index]; + } else { + trans =3D NULL; + } done: /* Caller will wait for this, so take a reference */ if (trans) refcount_inc(&trans->refcount); =20 - spin_unlock_bh(&trans_info->spinlock); - return trans; } =20 --=20 2.34.1 From nobody Mon Apr 6 20:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8B9E9C6FA82 for ; Fri, 2 Sep 2022 21:02:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230486AbiIBVCq (ORCPT ); Fri, 2 Sep 2022 17:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230450AbiIBVC1 (ORCPT ); Fri, 2 Sep 2022 17:02:27 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E51EAB2CFF for ; Fri, 2 Sep 2022 14:02:26 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id r141so2660118iod.4 for ; Fri, 02 Sep 2022 14:02:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=wXtVbgfVAjAnFG+gl8zfcyZNigB/A7fWYjmIjrEWnFw=; b=tJ5pt1iOrDE9HnmuU2z91c5o+GjTXTa8xAjYRYQKVx3qijRfKzjWWMIWGcjqfDgZ2v 0Sodk0RcMNFYfD6MJeZaUzOWwef4lr3T+anFkraj3Y8tKWIH4oMz3f+yMOX+mayO2b6+ owNRcbl8hwj2AQ/8o/gLPXdfcO5rdQbdnMcnF0YnsleKf3S+b6wqixm3f7hIe8OyD+6U xNZgPwXc66i3qahVCbNpAnQezUB0RnSaTm3BrdiP/RNh/9Bkwxk/mzBXefzHNXn4vWDo /aBIzL4jCT0IRBLTv9Qh4PCqdXatpTX+cF6TeJIh67N6OspPedGn34FuS9Qyk/nfOwrS Uw1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=wXtVbgfVAjAnFG+gl8zfcyZNigB/A7fWYjmIjrEWnFw=; b=tZCXO+oAyXahfl+QA+p/0/OPjDUeRcu5SDcj0AxWnK0aM96gQAYaiV33XHa4EeyCKW KSpkkpokaytw+JUxqAAKu55LtkBMvU2oNBWRFRZTS4XMJATHRVLfqFkdUewpfZ41+4wW SRVaSzrdPO0ujoGxRtl167ffVO99d6iQpMXNcKVZz2JxLNaPF7VokqO3YtmwF1ibyonI 2sOtGvcJ69ZORUUNNe1rA1310/NdY6x69WKafOiWo7AUydhng7RW+nLCw9U6fNErANuC 8EXdzdpZwmqDmuazHlgV/XFbLxoakRQOGYvVQBD0O1Mu26SmNRgQ7kZAaskSa9df1qmY uBBQ== X-Gm-Message-State: ACgBeo0yxXjD3jmhunoFB3VY1f8QVzsv3PP0RUoPJNdD7NuR1i2AxczW OTWevpwdD0qQOeQbxqKEd0EQQA== X-Google-Smtp-Source: AA6agR4HufdtD/9OxH2qjCZXSXxQ/SwmvJ369EXBIREDC4zPnp6YUXWazsZ5BRIui3Crg4Vudg3Z/w== X-Received: by 2002:a02:b60d:0:b0:343:5ddd:66b3 with SMTP id h13-20020a02b60d000000b003435ddd66b3mr20698508jam.8.1662152546588; Fri, 02 Sep 2022 14:02:26 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id i7-20020a0566022c8700b00689e718d971sm1259208iow.51.2022.09.02.14.02.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 14:02:26 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/6] net: ipa: simplify gsi_channel_trans_last() Date: Fri, 2 Sep 2022 16:02:16 -0500 Message-Id: <20220902210218.745873-5-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902210218.745873-1-elder@linaro.org> References: <20220902210218.745873-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Using a little logic we can simplify gsi_channel_trans_last(). The first condition in that function looks like this: if (trans_info->allocated_id !=3D trans_info->free_id) And if that's false, we proceed to the next one: if (trans_info->committed_id !=3D trans_info->allocated_id) Failure of the first test implies: trans_info->allocated_id =3D=3D trans_info->free_id And therefore, the second one can be rewritten this way: if (trans_info->committed_id !=3D trans_info->free_id) Substituting free_id for allocated_id and committed_id can also be done in the code blocks executed when these conditions yield true. The net result is that all three blocks for TX endpoints can be consolidated into just one. The two blocks of code at the end of that function (used for both TX and RX channels) can be similarly consolidated into a single block. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.c | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 0983a11409f2d..841a946bc286a 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -718,46 +718,27 @@ static struct gsi_trans *gsi_channel_trans_last(struc= t gsi_channel *channel) * before we disabled transmits, so check for that. */ if (channel->toward_ipa) { - /* The last allocated transaction precedes the first free */ - if (trans_info->allocated_id !=3D trans_info->free_id) { + /* The last allocated, committed, or pending transaction + * precedes the first free transaction. + */ + if (trans_info->pending_id !=3D trans_info->free_id) { trans_id =3D trans_info->free_id - 1; trans_index =3D trans_id % channel->tre_count; trans =3D &trans_info->trans[trans_index]; goto done; } - - /* Last committed transaction precedes the first allocated */ - if (trans_info->committed_id !=3D trans_info->allocated_id) { - trans_id =3D trans_info->allocated_id - 1; - trans_index =3D trans_id % channel->tre_count; - trans =3D &trans_info->trans[trans_index]; - goto done; - } - - /* Last pending transaction precedes the first committed */ - if (trans_info->pending_id !=3D trans_info->committed_id) { - trans_id =3D trans_info->committed_id - 1; - trans_index =3D trans_id % channel->tre_count; - trans =3D &trans_info->trans[trans_index]; - goto done; - } } =20 /* Otherwise (TX or RX) we want to wait for anything that * has completed, or has been polled but not released yet. * - * The last pending transaction precedes the first committed. + * The last completed or polled transaction precedes the + * first pending transaction. */ - if (trans_info->completed_id !=3D trans_info->pending_id) { + if (trans_info->polled_id !=3D trans_info->pending_id) { trans_id =3D trans_info->pending_id - 1; trans_index =3D trans_id % channel->tre_count; trans =3D &trans_info->trans[trans_index]; - goto done; - } - if (trans_info->polled_id !=3D trans_info->completed_id) { - trans_id =3D trans_info->completed_id - 1; - trans_index =3D trans_id % channel->tre_count; - trans =3D &trans_info->trans[trans_index]; } else { trans =3D NULL; } --=20 2.34.1 From nobody Mon Apr 6 20:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2346FC6FA82 for ; Fri, 2 Sep 2022 21:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230254AbiIBVCu (ORCPT ); Fri, 2 Sep 2022 17:02:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbiIBVCa (ORCPT ); Fri, 2 Sep 2022 17:02:30 -0400 Received: from mail-il1-x133.google.com (mail-il1-x133.google.com [IPv6:2607:f8b0:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E02BBADB8 for ; Fri, 2 Sep 2022 14:02:28 -0700 (PDT) Received: by mail-il1-x133.google.com with SMTP id v15so1805717iln.6 for ; Fri, 02 Sep 2022 14:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=keY88H+1hbyGiRZeqHCulNm4eRlJSKK4BM1mzktooc0=; b=ABPQzlV96Q16lH11eCbT2/RhU70y/fWPsS4Exd+elUdxXiWe579ocaIO3r994OB7th 160hfV1GscmW/buhdfA3u/8Dex3EB3cwsG88+xs8G6TGkYpiXLjvSrZRWfcZpdD4PMLT B9OCNmkRRffpls/tAQcT2tsgQmGTlbOS5UkpkFTHE58b6dAVUVZiCpyMqwoYE/ySXPIK 8SS0i2AhOmCbgpwI/xTBegZmujrpkuGVA0nQFph8kN4fu/v31tk9UZL9dXpPtaFfu8BB selIZu1pwurYCgrceVYLn6StBzoFW0TDj3GV2iaV0ZFsW7E6Jy4iXchry//DCEwndBn5 1NiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=keY88H+1hbyGiRZeqHCulNm4eRlJSKK4BM1mzktooc0=; b=YFJEjBS7BObXW8Z09OrTHLI0xyWnezc8MIqkfUVgXZwuGnzp7fz7Q1VC9rSme2pXF+ faoIODKXLw7m02dVwZDFfstHrKNhihVjkBWYHtMS+bf6OajDkpXzGZvxaGnvD0BsBxTT ikeBUXDmxttEqRVIwf56z5jJ5cLFaSrgMGiTFqpUk1RCuiV0/aGuPuU041csG+9XCrK5 ty8imGd8sPM034p9ydjETaCYRjWPQgvpeqXgqPQOaK0c9WbhYDWGh+iUua9NiJGsPT8i duwSgGuON+dQlyl4CXjHEdtV+oJr1pJuoFN5o2apASbdPeP/WuJ7qv3gSpVnNGJlDvTJ sDRQ== X-Gm-Message-State: ACgBeo3NmF/1vox6dOCGIcLjK3WRy5lDFGRcE+XdAmHtwKIfosmUT5cJ e3IYgrogPUf3zThJdymGW3/6BQ== X-Google-Smtp-Source: AA6agR7QBR4VEiK7Ff13qBJNczp9ygOUOj0dKr2/XrzzwElGRrNV9oi9nouw9sUmWsMLlb6vVIckfA== X-Received: by 2002:a05:6e02:148a:b0:2ea:37bc:b312 with SMTP id n10-20020a056e02148a00b002ea37bcb312mr20726800ilk.96.1662152547675; Fri, 02 Sep 2022 14:02:27 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id i7-20020a0566022c8700b00689e718d971sm1259208iow.51.2022.09.02.14.02.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 14:02:27 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 5/6] net: ipa: further simplify gsi_channel_trans_last() Date: Fri, 2 Sep 2022 16:02:17 -0500 Message-Id: <20220902210218.745873-6-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902210218.745873-1-elder@linaro.org> References: <20220902210218.745873-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Do a little more refactoring in gsi_channel_trans_last() to simplify it further. The resulting code should behave exactly as before. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi.c | 46 +++++++++++++++++-------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/drivers/net/ipa/gsi.c b/drivers/net/ipa/gsi.c index 841a946bc286a..16df699009a86 100644 --- a/drivers/net/ipa/gsi.c +++ b/drivers/net/ipa/gsi.c @@ -710,42 +710,32 @@ static void gsi_evt_ring_program(struct gsi *gsi, u32= evt_ring_id) static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channe= l) { struct gsi_trans_info *trans_info =3D &channel->trans_info; + u32 pending_id =3D trans_info->pending_id; struct gsi_trans *trans; - u16 trans_index; u16 trans_id; =20 - /* There is a small chance a TX transaction got allocated just - * before we disabled transmits, so check for that. - */ - if (channel->toward_ipa) { - /* The last allocated, committed, or pending transaction + if (channel->toward_ipa && pending_id !=3D trans_info->free_id) { + /* There is a small chance a TX transaction got allocated + * just before we disabled transmits, so check for that. + * The last allocated, committed, or pending transaction * precedes the first free transaction. */ - if (trans_info->pending_id !=3D trans_info->free_id) { - trans_id =3D trans_info->free_id - 1; - trans_index =3D trans_id % channel->tre_count; - trans =3D &trans_info->trans[trans_index]; - goto done; - } - } - - /* Otherwise (TX or RX) we want to wait for anything that - * has completed, or has been polled but not released yet. - * - * The last completed or polled transaction precedes the - * first pending transaction. - */ - if (trans_info->polled_id !=3D trans_info->pending_id) { - trans_id =3D trans_info->pending_id - 1; - trans_index =3D trans_id % channel->tre_count; - trans =3D &trans_info->trans[trans_index]; + trans_id =3D trans_info->free_id - 1; + } else if (trans_info->polled_id !=3D pending_id) { + /* Otherwise (TX or RX) we want to wait for anything that + * has completed, or has been polled but not released yet. + * + * The last completed or polled transaction precedes the + * first pending transaction. + */ + trans_id =3D pending_id - 1; } else { - trans =3D NULL; + return NULL; } -done: + /* Caller will wait for this, so take a reference */ - if (trans) - refcount_inc(&trans->refcount); + trans =3D &trans_info->trans[trans_id % channel->tre_count]; + refcount_inc(&trans->refcount); =20 return trans; } --=20 2.34.1 From nobody Mon Apr 6 20:11:05 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B64ADC6FA82 for ; Fri, 2 Sep 2022 21:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231152AbiIBVCx (ORCPT ); Fri, 2 Sep 2022 17:02:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbiIBVCb (ORCPT ); Fri, 2 Sep 2022 17:02:31 -0400 Received: from mail-io1-xd32.google.com (mail-io1-xd32.google.com [IPv6:2607:f8b0:4864:20::d32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 068B6BD742 for ; Fri, 2 Sep 2022 14:02:29 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id h78so2614377iof.13 for ; Fri, 02 Sep 2022 14:02:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=Sg94S1ohGjSO+2FVqvQ4ZE3HnavccZA0F79TKZotqVs=; b=o9qQ43NUmTFDtsWINhDRhOkVGXDvg/H28BHjXIDDAEPud8d9lSZEHUA9LlfLcwHDva dDJrZm3qqB7nsHYvewhltyadSReDKbLEevaB19KsVU52naGDx6JOHOJbQoZRzgZSIefV Mjh8BpDYLeeU7W+p+wCeM3NkaxlEUjad5u5Y3KDzZjrW9rc3n4EkJOcAgM3qWWCco72i nK+I1s6KAqk9x+sVXzB7SYmj6Jr+vuF3BFsPwSrc4l0Tl8vi5J0aGvw4SSXChJvldh9L SWd3rTClLlqPJ08BIsCVeKPVQ8STXdNwTyxLN4xcn/gUFRdqFD7JOoY9w3LZqYgsvmId 3jpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=Sg94S1ohGjSO+2FVqvQ4ZE3HnavccZA0F79TKZotqVs=; b=hfjEv5At7i5aSOrpiknPBixiELReQk0SHjeKpdtsdB2AfkRnizpLyaCfWVetVPUdKP CUFUO1cnhUIflhBDtjkuRleJmbLy0f/ko6UFDkJyoVAYU7DMMIQs9Xeg8X6t34By8vw7 /XKZ0ueCK1e+yH5ATOYDnT4Cwy74epNHfYyf5bVdU5sUBn6vwVlfJ527tkDj+CLaMmRr mKt2RJ/RS/dwwqzw/62aFNwMzNxKGKgd88jQ3OLReCY+Jw0M52tANNpc43jjOJz3Hy8y az878jRoEg5Rc+iLXb1ZGUQ90E0IxYT+pSWTF3mMF2X95nVdBI/cpFhA34cf9Ski9gPP TdPg== X-Gm-Message-State: ACgBeo2p2LhaXHzMI+NGfLblA0bes+tHVyQ/DhVaZ4Ok8ksVDt1LLu/E PfGblaWUEehqvtTAe7jsUnUw4w== X-Google-Smtp-Source: AA6agR4bipgwhYJcj70+tEd37INbaqRP3sa2haOjLbdU0WafJ0IULWIhc59GMUjKLG7TzCpXBhBeFQ== X-Received: by 2002:a05:6638:2613:b0:346:e2c5:aa4e with SMTP id m19-20020a056638261300b00346e2c5aa4emr20374986jat.160.1662152548689; Fri, 02 Sep 2022 14:02:28 -0700 (PDT) Received: from presto.localdomain ([98.61.227.136]) by smtp.gmail.com with ESMTPSA id i7-20020a0566022c8700b00689e718d971sm1259208iow.51.2022.09.02.14.02.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Sep 2022 14:02:28 -0700 (PDT) From: Alex Elder To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com Cc: mka@chromium.org, evgreen@chromium.org, bjorn.andersson@linaro.org, quic_cpratapa@quicinc.com, quic_avuyyuru@quicinc.com, quic_jponduru@quicinc.com, quic_subashab@quicinc.com, elder@kernel.org, netdev@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next 6/6] net: ipa: verify a few more IDs Date: Fri, 2 Sep 2022 16:02:18 -0500 Message-Id: <20220902210218.745873-7-elder@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220902210218.745873-1-elder@linaro.org> References: <20220902210218.745873-1-elder@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The completed transaction list is used in gsi_channel_trans_complete() to return the next transaction in completed state. Add some temporary checks to verify the transaction indicated by the completed ID matches the one first in this list. Similarly, we use the pending and completed transaction lists when cancelling pending transactions in gsi_channel_trans_cancel_pending(). Add temporary checks there to verify the transactions indicated by IDs match those tracked by these lists. Signed-off-by: Alex Elder --- drivers/net/ipa/gsi_trans.c | 46 ++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/drivers/net/ipa/gsi_trans.c b/drivers/net/ipa/gsi_trans.c index b4a6f2b563566..05ab4d052c68b 100644 --- a/drivers/net/ipa/gsi_trans.c +++ b/drivers/net/ipa/gsi_trans.c @@ -237,8 +237,24 @@ gsi_channel_trans_mapped(struct gsi_channel *channel, = u32 index) /* Return the oldest completed transaction for a channel (or null) */ struct gsi_trans *gsi_channel_trans_complete(struct gsi_channel *channel) { - return list_first_entry_or_null(&channel->trans_info.complete, - struct gsi_trans, links); + struct gsi_trans_info *trans_info =3D &channel->trans_info; + u16 trans_id =3D trans_info->completed_id; + struct gsi_trans *trans; + + trans =3D list_first_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + + if (!trans) { + WARN_ON(trans_id !=3D trans_info->pending_id); + return NULL; + } + + if (!WARN_ON(trans_id =3D=3D trans_info->pending_id)) { + trans_id %=3D channel->tre_count; + WARN_ON(trans !=3D &trans_info->trans[trans_id]); + } + + return trans; } =20 /* Move a transaction from the allocated list to the committed list */ @@ -690,6 +706,8 @@ void gsi_channel_trans_cancel_pending(struct gsi_channe= l *channel) { struct gsi_trans_info *trans_info =3D &channel->trans_info; struct gsi_trans *trans; + struct gsi_trans *first; + struct gsi_trans *last; bool cancelled; =20 /* channel->gsi->mutex is held by caller */ @@ -701,11 +719,33 @@ void gsi_channel_trans_cancel_pending(struct gsi_chan= nel *channel) =20 list_splice_tail_init(&trans_info->pending, &trans_info->complete); =20 + first =3D list_first_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + last =3D list_last_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); =20 + /* All pending transactions are now completed */ + WARN_ON(cancelled !=3D (trans_info->pending_id !=3D + trans_info->committed_id)); + + trans_info->pending_id =3D trans_info->committed_id; + /* Schedule NAPI polling to complete the cancelled transactions */ - if (cancelled) + if (cancelled) { + u16 trans_id; + napi_schedule(&channel->napi); + + trans_id =3D trans_info->completed_id; + trans =3D &trans_info->trans[trans_id % channel->tre_count]; + WARN_ON(trans !=3D first); + + trans_id =3D trans_info->pending_id - 1; + trans =3D &trans_info->trans[trans_id % channel->tre_count]; + WARN_ON(trans !=3D last); + } } =20 /* Issue a command to read a single byte from a channel */ --=20 2.34.1