Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp2146884pxb; Sun, 30 Jan 2022 06:34:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJxLBDvILIcYMuE1NgJG3Yg1HWI+w/mLw28IqCayN+kkg9UhM9CnRXbonBRAduUb7eVxNcod X-Received: by 2002:a17:903:4052:: with SMTP id n18mr16907416pla.88.1643553272056; Sun, 30 Jan 2022 06:34:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643553272; cv=none; d=google.com; s=arc-20160816; b=wpUkUj6LhA3Go9wMN7ROpjjGOE32kC6duRdm97Wgs4VOZ4J+xowJLEzQK1UGgR05Rf U9zpxKjLQ2FAL49JSmYEgBNKxTi/dQ0zdTqP84zDxm4uDnMW7TB/sl6sf+4dvZN+LgRs ZvREg7Z+DDNFnQvlHhRXVgVuy8NKQQDq5EVOTnbzgCBN0rd7fQHiaRiqQntCxdc3Vr6v xs8XMZXqHFm9LPsIFZAk+OMKLeiukl1D8dUV2AGukR+jTNpui4Za1oqq3VFB2eX4/AjQ aZfGHEN+BNmCjNF17nlR+HulLH9JPU+VPVikADODUqq19u5kUFFb81qdHF+sox+9LAvH oItg== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=AYAaZXuT3OiseW3dOwFsQwLfxqLwcr7AEtxD39fmfvk=; b=BGGrv6b6aA9HpqHFo/igFrxYrJIl45p60ToJSJMSNbuzuTNGD1c6vb2haJFCDYUP3d r2lyF5q94had4gT1iKmQ/77vJ1mF2mLniCtdfSGajAjuJTJ5xj2N3fTpDMkdtO/0evD4 FmGbvr79W4WxWDVWmLzL846Uwd8yJ6Vw6usyhDXmICo6b78LnuAxvi7uIr4z43Wb6cEy l4Vtdf1r+19kFagVyff0OZbgJoM6KH0o8Cl86VwtDfmhPgqeRb/RgZGWT+JQ/ckJqquJ QQbehkbvGT36T4KGhkdYtYf7utmWJCjN0flTGrPPDm8z4lpVTOsDJ3oNQBBTkO2NfrH2 u0lA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iBllToQD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d12si12646230pfv.38.2022.01.30.06.34.01; Sun, 30 Jan 2022 06:34:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=iBllToQD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347179AbiA1II1 (ORCPT + 99 others); Fri, 28 Jan 2022 03:08:27 -0500 Received: from mga18.intel.com ([134.134.136.126]:11371 "EHLO mga18.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229758AbiA1IIY (ORCPT ); Fri, 28 Jan 2022 03:08:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643357304; x=1674893304; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=pITGzVCbZRtpq2q1aOKadxl2UAcX3Welnaw3bRtitQo=; b=iBllToQDx84abThRyPqwKZrzGLa9jBnVY3ybO6LSilOHu7tErHBvc4v5 Gm2o00DFv0vfsH6bTlVywTFORfOklGY6/+zWvaDU/t0g1J4ZlFjErcKBu /IQymy6ZQ86VBOgySpyZln2NIbXovFMbveqjnOkOikV+vA013981D+HhL 9KUKf/TNlmkn7g1vRMiJy7MOHSSNEOgk3PUinyt1Y2grY/P1uljwzp0fa F2s90QZwbypiUPXvJjXf8T+AO2p0P8x1khtvXnZRDSfZsOIBy5XlZbusQ mJNxEKHRxWXUXs7p9v0Febh4a4QWcGZK+BDD7pyM5Rl5ESE88U4B/aULR Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10240"; a="230651803" X-IronPort-AV: E=Sophos;i="5.88,323,1635231600"; d="scan'208";a="230651803" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Jan 2022 00:08:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,323,1635231600"; d="scan'208";a="536041501" Received: from npg-dpdk-haiyue-1.sh.intel.com ([10.67.118.194]) by orsmga008.jf.intel.com with ESMTP; 28 Jan 2022 00:08:08 -0800 From: Haiyue Wang To: netdev@vger.kernel.org Cc: Haiyue Wang , Jeroen de Borst , Catherine Sullivan , David Awogbemila , "David S. Miller" , Jakub Kicinski , Willem de Bruijn , Bailey Forrest , Shailend Chand , Sagi Shahar , Yangchun Fu , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v1] gve: fix the wrong AdminQ buffer queue index check Date: Fri, 28 Jan 2022 15:38:22 +0800 Message-Id: <20220128073824.7209-1-haiyue.wang@intel.com> X-Mailer: git-send-email 2.35.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The 'tail' and 'head' are 'unsigned int' type free-running count, when 'head' is overflow, the 'int i (= tail) < u32 head' will be false: Only '- loop 0: idx = 63' result is shown, so it needs to use 'int' type to compare, it can handle the overflow correctly. typedef uint32_t u32; int main() { u32 tail, head; int stail, shead; int i, loop; tail = 0xffffffff; head = 0x00000000; for (i = tail, loop = 0; i < head; i++) { unsigned int idx = i & 63; printf("+ loop %d: idx = %u\n", loop++, idx); } stail = tail; shead = head; for (i = stail, loop = 0; i < shead; i++) { unsigned int idx = i & 63; printf("- loop %d: idx = %u\n", loop++, idx); } return 0; } Fixes: 5cdad90de62c ("gve: Batch AQ commands for creating and destroying queues.") Signed-off-by: Haiyue Wang --- drivers/net/ethernet/google/gve/gve_adminq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/net/ethernet/google/gve/gve_adminq.c b/drivers/net/ethernet/google/gve/gve_adminq.c index 2ad7f57f7e5b..f7621ab672b9 100644 --- a/drivers/net/ethernet/google/gve/gve_adminq.c +++ b/drivers/net/ethernet/google/gve/gve_adminq.c @@ -301,7 +301,7 @@ static int gve_adminq_parse_err(struct gve_priv *priv, u32 status) */ static int gve_adminq_kick_and_wait(struct gve_priv *priv) { - u32 tail, head; + int tail, head; int i; tail = ioread32be(&priv->reg_bar0->adminq_event_counter); -- 2.35.0