From patchwork Fri Sep 2 21:02:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 602212 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 12B11C6FA83 for ; Fri, 2 Sep 2022 21:02:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230468AbiIBVC1 (ORCPT ); Fri, 2 Sep 2022 17:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230450AbiIBVCY (ORCPT ); Fri, 2 Sep 2022 17:02:24 -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 ADBDBB81F4 for ; Fri, 2 Sep 2022 14:02:23 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id h78so2614189iof.13 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=VT2MfbFzjVAf4EetiF0e31sgvqWoZtGax0u/BNN/l5JCg3wGUn9nY50hNKOHGzNb8j YsYMROgI2zgBB7rhwu8Hu8PO1WopT/kw2zhSmHROE7OnEDzRzykV0LZabrt3CLyhy9RR /ideaJLRekRP0R3JaFc6EDPbTuVGwS5Ba6h0XPWAgzCZ6mrnFKcR4xWjTaVoLKfsUu9H IGMOOW8Tm4ndw0T0lEfzNiZrur+bvYv5SPk8c4NiguE3hCQY75Ptd5glZCipVoammt3Q MA9m11BXQoq12VcB2aay9N6+TVGbNnS/HaHbBuOCwV1JHt+0Jp2ujMUVMo74hdjUGbQT /Yjw== X-Gm-Message-State: ACgBeo3nK6GgtClK8+FPDmaewAuJNfboNminIoMsXoidTa2P/oqC6Gk1 C3Wflu4I94AKswjw8YnJBEjB+A== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 evt_ring_id) static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channel) { struct gsi_trans_info *trans_info = &channel->trans_info; - const struct list_head *list; struct gsi_trans *trans; spin_lock_bh(&trans_info->spinlock); @@ -719,29 +718,30 @@ static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channel) * before we disabled transmits, so check for that. */ if (channel->toward_ipa) { - list = &trans_info->alloc; - if (!list_empty(list)) + trans = list_last_entry_or_null(&trans_info->alloc, + struct gsi_trans, links); + if (trans) goto done; - list = &trans_info->committed; - if (!list_empty(list)) + trans = list_last_entry_or_null(&trans_info->committed, + struct gsi_trans, links); + if (trans) goto done; - list = &trans_info->pending; - if (!list_empty(list)) + trans = list_last_entry_or_null(&trans_info->pending, + struct gsi_trans, links); + if (trans) goto done; } /* Otherwise (TX or RX) we want to wait for anything that * has completed, or has been polled but not released yet. */ - list = &trans_info->complete; - if (!list_empty(list)) + trans = list_last_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + if (trans) goto done; - list = &trans_info->polled; - if (list_empty(list)) - list = NULL; + trans = list_last_entry_or_null(&trans_info->polled, + struct gsi_trans, links); done: - trans = 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; #define GSI_RING_ELEMENT_SIZE 16 /* bytes; must be a power of 2 */ +/** + * 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__ = (ptr); \ + struct list_head *pos__ = READ_ONCE(head__->prev); \ + pos__ != 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 = &trans->gsi->channel[trans->channel_id]; struct gsi_trans_info *trans_info = &channel->trans_info; - u16 trans_index; spin_lock_bh(&trans_info->spinlock); list_move_tail(&trans->links, &trans_info->polled); - trans = list_first_entry(&trans_info->polled, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); /* This completed transaction is now polled */ trans_info->completed_id++; - - WARN_ON(trans_info->polled_id == trans_info->completed_id); - trans_index = trans_info->polled_id % channel->tre_count; - WARN_ON(trans != &trans_info->trans[trans_index]); } /* 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 = &trans->gsi->channel[trans->channel_id]; refcount_t *refcount = &trans->refcount; struct gsi_trans_info *trans_info; - struct gsi_trans *polled; - u16 trans_index; bool last; /* 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); - polled = list_first_entry_or_null(&trans_info->polled, - struct gsi_trans, links); - spin_unlock_bh(&trans_info->spinlock); if (!last) @@ -456,14 +442,6 @@ void gsi_trans_free(struct gsi_trans *trans) /* This transaction is now free */ trans_info->polled_id++; - if (polled) { - trans_index = trans_info->polled_id % channel->tre_count; - WARN_ON(polled != &trans_info->trans[trans_index]); - } else { - WARN_ON(trans_info->polled_id != - trans_info->completed_id); - } - /* Releasing the reserved TREs implicitly frees the sgl[] and * (if present) info[] arrays, plus the transaction itself. */ From patchwork Fri Sep 2 21:02:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 602429 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 63C06C6FA8B for ; Fri, 2 Sep 2022 21:02:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230471AbiIBVC1 (ORCPT ); Fri, 2 Sep 2022 17:02:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230459AbiIBVC0 (ORCPT ); Fri, 2 Sep 2022 17:02:26 -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 AE9E6B4424 for ; Fri, 2 Sep 2022 14:02:24 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id c4so2663026iof.3 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=tZPgXGiZ3vLcD1iVAv1GSP1ErbgMGLcPXsbIs9Ou6b9iFqA25vneFn8PYYo8tlBcpq nS+QnufZAgaoL7YcmSIuIMRb3PKxpsOztA9K8pu/gzQHitEmd9wcce+WG40ezHEh6pyv RUrysWTUW5rW13mxRDWu6+jtVNtrNyZqZKCQFbvittUxgyN32WOPZgTW66VG7yKeki86 hRFfIiDTsxRhpL3h690n8h02TeTl9OUzfE4Imm8BDUBKsLDFUSDwHdcHNRPHOKm9Y5Xk 2GIbM2rx9VKqrd4VHpBZLtrZinehk9iXI43bVw/eHMTcOHAdI1Rmo+z8wUmscRTsooFf GVyQ== X-Gm-Message-State: ACgBeo0jQnkoSco/it2+XrgwNXguhebJO/tWpy/W9sYYRCi4Ks7wWdr7 bWXathDWrMrV9Yo0RfaiLiewYg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 = &channel->trans_info; struct gsi_trans *trans; + u16 trans_index; + u16 trans_id; spin_lock_bh(&trans_info->spinlock); @@ -718,10 +720,14 @@ static struct gsi_trans *gsi_channel_trans_last(struct gsi_channel *channel) * before we disabled transmits, so check for that. */ if (channel->toward_ipa) { - trans = 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 != trans_info->free_id) { + trans_id = trans_info->free_id - 1; + trans_index = trans_id % channel->tre_count; + trans = &trans_info->trans[trans_index]; goto done; + } + trans = list_last_entry_or_null(&trans_info->committed, struct gsi_trans, links); if (trans) From patchwork Fri Sep 2 21:02:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 602211 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 BE376C6FA89 for ; Fri, 2 Sep 2022 21:02:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230459AbiIBVC2 (ORCPT ); Fri, 2 Sep 2022 17:02:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbiIBVC0 (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 EF321B5A78 for ; Fri, 2 Sep 2022 14:02:25 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id c4so2663065iof.3 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=JMLyn/rV+uh0CnRkm8Ob3EbpViXUovQcXSEY+SGQe366OUBrtRfFqnRfbI8y5LVCrv go9Vq8Ezr8oT8ZHl1HnAQ2MQrEfU2KdzCg2Z+oIJJuizQ8PDopoKJ2VVxgC7bbMeu7/f IwFuP/QpvU+C+lpP1lZsew7CTqDYe9FOY+YDb2x0SKeivPr459frxksdsPJ/TlBz4sNt 0OG3J5jACrQkecH7VBYU7cuaXWbMOXS9T88ZuN3nFHwhvci/qguvBzUQQw1JOWtgJWH5 iI1eGrwvMA6/flkLvNTVecc23fEWbZa6FnnNF0skqWPV20/v7iYg6RMVXMs/t6BpJD1S bGiQ== X-Gm-Message-State: ACgBeo1Or580Z03KwGoS4fRE1p07Pc2YcRECle7kvv+bHgVL6EgWroRH 6b2yOFB+EPbKCFUmAbPQCIRL+Q== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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; - 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(struct gsi_channel *channel) goto done; } - trans = 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 != trans_info->allocated_id) { + trans_id = trans_info->allocated_id - 1; + trans_index = trans_id % channel->tre_count; + trans = &trans_info->trans[trans_index]; goto done; - trans = 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 != trans_info->committed_id) { + trans_id = trans_info->committed_id - 1; + trans_index = trans_id % channel->tre_count; + trans = &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 pending transaction precedes the first committed. */ - trans = list_last_entry_or_null(&trans_info->complete, - struct gsi_trans, links); - if (trans) + if (trans_info->completed_id != trans_info->pending_id) { + trans_id = trans_info->pending_id - 1; + trans_index = trans_id % channel->tre_count; + trans = &trans_info->trans[trans_index]; goto done; - trans = list_last_entry_or_null(&trans_info->polled, - struct gsi_trans, links); + } + if (trans_info->polled_id != trans_info->completed_id) { + trans_id = trans_info->completed_id - 1; + trans_index = trans_id % channel->tre_count; + trans = &trans_info->trans[trans_index]; + } else { + trans = NULL; + } done: /* Caller will wait for this, so take a reference */ if (trans) refcount_inc(&trans->refcount); - spin_unlock_bh(&trans_info->spinlock); - return trans; } From patchwork Fri Sep 2 21:02:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 602428 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 38885C6FA83 for ; Fri, 2 Sep 2022 21:02:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230465AbiIBVCc (ORCPT ); Fri, 2 Sep 2022 17:02:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229999AbiIBVC2 (ORCPT ); Fri, 2 Sep 2022 17:02:28 -0400 Received: from mail-io1-xd30.google.com (mail-io1-xd30.google.com [IPv6:2607:f8b0:4864:20::d30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3750D266F for ; Fri, 2 Sep 2022 14:02:27 -0700 (PDT) Received: by mail-io1-xd30.google.com with SMTP id n202so2644830iod.6 for ; Fri, 02 Sep 2022 14:02:27 -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=hBRHLpqezoahJGXZqLrpU2bugCxlriB2Fi8aP2j7PGBq93ZftBqPqCZsMptMQe4ESJ kYTWUWbqb9AmmLmNcFjlAG/vmxlUpdg0jErgZCuqOT3ZoGxdDmvI3zZ32dr1ZIeQwQQU QoNHZEXljqc6kIsjzTgUTE8kGxw6iVig5QfKhhnxgVMAPU9q5c6jJp3CnOYQo9BY812w RqsEyaimh+vrrixJPwSKJgp9VPtUtXiRU7XrFqw5w5gsDeFijpNIhuIJ/nEMfeJ8o6/W jrba13gWSioz6wW24MRVYjpCLbSj83+4oRd9WmoP1I4X+MvB1tK4363rDk5IpNUojSR5 0YzQ== X-Gm-Message-State: ACgBeo3G6OqMOiMJO78PsJo3TzyadnACONCb9CAw48l41FRwe+CwvQnk isfPavKrTOWeBk7zha6T94W1Ng== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 != trans_info->free_id) And if that's false, we proceed to the next one: if (trans_info->committed_id != trans_info->allocated_id) Failure of the first test implies: trans_info->allocated_id == trans_info->free_id And therefore, the second one can be rewritten this way: if (trans_info->committed_id != 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(struct 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 != trans_info->free_id) { + /* The last allocated, committed, or pending transaction + * precedes the first free transaction. + */ + if (trans_info->pending_id != trans_info->free_id) { trans_id = trans_info->free_id - 1; trans_index = trans_id % channel->tre_count; trans = &trans_info->trans[trans_index]; goto done; } - - /* Last committed transaction precedes the first allocated */ - if (trans_info->committed_id != trans_info->allocated_id) { - trans_id = trans_info->allocated_id - 1; - trans_index = trans_id % channel->tre_count; - trans = &trans_info->trans[trans_index]; - goto done; - } - - /* Last pending transaction precedes the first committed */ - if (trans_info->pending_id != trans_info->committed_id) { - trans_id = trans_info->committed_id - 1; - trans_index = trans_id % channel->tre_count; - trans = &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 pending transaction precedes the first committed. + * The last completed or polled transaction precedes the + * first pending transaction. */ - if (trans_info->completed_id != trans_info->pending_id) { + if (trans_info->polled_id != trans_info->pending_id) { trans_id = trans_info->pending_id - 1; trans_index = trans_id % channel->tre_count; trans = &trans_info->trans[trans_index]; - goto done; - } - if (trans_info->polled_id != trans_info->completed_id) { - trans_id = trans_info->completed_id - 1; - trans_index = trans_id % channel->tre_count; - trans = &trans_info->trans[trans_index]; } else { trans = NULL; } From patchwork Fri Sep 2 21:02:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 602210 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 962BBC6FA8B for ; Fri, 2 Sep 2022 21:02:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230475AbiIBVCe (ORCPT ); Fri, 2 Sep 2022 17:02:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230473AbiIBVC3 (ORCPT ); Fri, 2 Sep 2022 17:02:29 -0400 Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E085BB01A for ; Fri, 2 Sep 2022 14:02:28 -0700 (PDT) Received: by mail-il1-x130.google.com with SMTP id r7so1800654ile.11 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=ZsoJbxIz9AZTnzp3X2dC3xx4EdHUQcuPg9AYvIIIn+D6UxMiQZe9eY4PbTLKf/Zeo3 o8oiBPT7dkCef/JQl4pvXtkpUkgvOJWXoFO+ckKjqRKAiu51wbef3Q4uVV7048lEjtb6 T57cK9EG2lh2jgrKV67NlMOsXysi1POEYZkTo4wSAZYw7HUJLkguJYhnlvFZIRyD1lQI 2H/125yG4AiJyE6NIY0Rg31yHf3kr+rxyTtQ/kVsRXPhXNwcd9nBwm6XsMehCS++v0Br gkcxHl9i4qTY6hup1f5SY6vak4XiOolX+LJ2isSHh9xtIpmhfhpSV6TDuRbyiLIEXChj m0yg== X-Gm-Message-State: ACgBeo2WHrheQdJZpBvyDOKNYx8zqtdfXc7AJs+oDq0IiIAQBQMN988q 73SG4cMOj3DiygJZXw8jhV8qEg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 *channel) { struct gsi_trans_info *trans_info = &channel->trans_info; + u32 pending_id = trans_info->pending_id; struct gsi_trans *trans; - u16 trans_index; u16 trans_id; - /* 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 != 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 != trans_info->free_id) { - trans_id = trans_info->free_id - 1; - trans_index = trans_id % channel->tre_count; - trans = &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 != trans_info->pending_id) { - trans_id = trans_info->pending_id - 1; - trans_index = trans_id % channel->tre_count; - trans = &trans_info->trans[trans_index]; + trans_id = trans_info->free_id - 1; + } else if (trans_info->polled_id != 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 = pending_id - 1; } else { - trans = NULL; + return NULL; } -done: + /* Caller will wait for this, so take a reference */ - if (trans) - refcount_inc(&trans->refcount); + trans = &trans_info->trans[trans_id % channel->tre_count]; + refcount_inc(&trans->refcount); return trans; } From patchwork Fri Sep 2 21:02:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Elder X-Patchwork-Id: 602427 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 5A077C6FA83 for ; Fri, 2 Sep 2022 21:02:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230515AbiIBVCn (ORCPT ); Fri, 2 Sep 2022 17:02:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229583AbiIBVCb (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 05ADDBD4F6 for ; Fri, 2 Sep 2022 14:02:29 -0700 (PDT) Received: by mail-io1-xd32.google.com with SMTP id i77so2639317ioa.7 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=8OssJu9y2SR5IUqrD2OU/pp8S//ei4jP8ZvdJTccIsOJ/+VoRGcTtwVAmtg/g26HjN aKhwudn4sZ3rMudl6MfJM1TAabv4FtbI7RRUfOrebPlga5MWpBH8R6crjEeFQ+s3oz0B iyiGNntwtzgUra2dPaG+bkyiNcu1qcbI19SbwAeBXe+bdUsV9azraKg7Ueil2LZYfbBc YSymXtXYXJmRl+artkGTZ+8QRFkLRi8J582t/bXcUZnv6M/PPIpptfxrXKPyqwufA3DL wDVquNACKMNLyHeUGpFxqnDKlW42fzqWC0a1TR3fvyfcAC+M8iCkxFD/2vhW0cLQGwAH O7mA== X-Gm-Message-State: ACgBeo1Oa51EPmPFvvMwXB2jRVIVNIIj03NFigJ7AaRkPyhlknvM41zD b261g9eCDgtwdMQBDZ9rc/1jOA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@vger.kernel.org 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 = &channel->trans_info; + u16 trans_id = trans_info->completed_id; + struct gsi_trans *trans; + + trans = list_first_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + + if (!trans) { + WARN_ON(trans_id != trans_info->pending_id); + return NULL; + } + + if (!WARN_ON(trans_id == trans_info->pending_id)) { + trans_id %= channel->tre_count; + WARN_ON(trans != &trans_info->trans[trans_id]); + } + + return trans; } /* Move a transaction from the allocated list to the committed list */ @@ -690,6 +706,8 @@ void gsi_channel_trans_cancel_pending(struct gsi_channel *channel) { struct gsi_trans_info *trans_info = &channel->trans_info; struct gsi_trans *trans; + struct gsi_trans *first; + struct gsi_trans *last; bool cancelled; /* channel->gsi->mutex is held by caller */ @@ -701,11 +719,33 @@ void gsi_channel_trans_cancel_pending(struct gsi_channel *channel) list_splice_tail_init(&trans_info->pending, &trans_info->complete); + first = list_first_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + last = list_last_entry_or_null(&trans_info->complete, + struct gsi_trans, links); + spin_unlock_bh(&trans_info->spinlock); + /* All pending transactions are now completed */ + WARN_ON(cancelled != (trans_info->pending_id != + trans_info->committed_id)); + + trans_info->pending_id = 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 = trans_info->completed_id; + trans = &trans_info->trans[trans_id % channel->tre_count]; + WARN_ON(trans != first); + + trans_id = trans_info->pending_id - 1; + trans = &trans_info->trans[trans_id % channel->tre_count]; + WARN_ON(trans != last); + } } /* Issue a command to read a single byte from a channel */