Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp301625rwb; Fri, 2 Sep 2022 14:33:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR6wxCW7fKYET0iXaDpTh531Luo9aQnRL4wH2Igv+wnA92+6WcEhFx00aks/dcOU8ht5UFfS X-Received: by 2002:a05:6402:e96:b0:443:a086:e3e8 with SMTP id h22-20020a0564020e9600b00443a086e3e8mr35297255eda.330.1662154384002; Fri, 02 Sep 2022 14:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662154383; cv=none; d=google.com; s=arc-20160816; b=yztyJ8KyzrWVL0LLbwb2xA8fohMfzp4g1L1usdEr/TGvxWF0rqVsitcHaDIiek1xN3 MNQxIe2P0w0xiHW6OptiajIUJU9M8cIufPtQvNvRt2g7psluvIFuoU1Ay8/lO7qz1H/X Vsy4AOykJpKP7BHwlzNqmIVbGVLxgb0/8Q1pwDG9N35v+0ai9n6/YeaY5KJcgH2D70m2 CzlD+N75ThWBqwO5UJ8csl69tL6d+xKkceO1iQM0pInjhcso2eYw2kunn/k/5w3ta1Fq iQV5h+IKoa60rLEN3NnaHpydcLzqyMWavdOxT8GhKMm8cAOF34Hh+68QUE2jZL31/5q3 35kQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Sg94S1ohGjSO+2FVqvQ4ZE3HnavccZA0F79TKZotqVs=; b=xaqG6+iy74Pz/d9apJ21pPghGEPbTx4YlM948MxMSLt4np8qHiNkSMxoAZCzyWZXSm WhLDIdNXGxyzAckMYpw25OtyexOWV5h3x2GpP9YUiOaRa50XB8Kp83hg0xAfJylRyp+7 z/JwCtnFGk/JZpie2AZYDBeFV0HU5hYE/BSwYrmBu+NMGfQQKuKsDgW+ZOdv6CxgMzv+ 0cZdzb7RkxTzmPPuzrsXTIqMmCjrnOz2/HN4qb/fcswradwIMaPKcg6/1vzE9rmJARNS 2tuvZu2vQXgSo/U2TvToXOR1NsWKIniPlkwEEFpI9msgvYCFVMhOvBiBiciXbORPQF2C 4XJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=o9qQ43NU; 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=linaro.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k18-20020a50c092000000b0043bb9745c2esi2714639edf.172.2022.09.02.14.32.38; Fri, 02 Sep 2022 14:33:03 -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=@linaro.org header.s=google header.b=o9qQ43NU; 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=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231151AbiIBVCw (ORCPT + 99 others); Fri, 2 Sep 2022 17:02:52 -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-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: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 */ -- 2.34.1