From patchwork Sat Oct 22 07:25:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 7512 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp1105041wrr; Sat, 22 Oct 2022 01:33:58 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4VEoL1jV25oaBCSKburMRoi9uwqJQItru2Fgyb3EZMDzt1jCzPM8SA64riU0c3vegMxusI X-Received: by 2002:a17:903:2284:b0:178:349b:d21b with SMTP id b4-20020a170903228400b00178349bd21bmr23362469plh.49.1666427638584; Sat, 22 Oct 2022 01:33:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666427638; cv=none; d=google.com; s=arc-20160816; b=oxZ5LVFheAY+GSH4gs0093doZSEd/Yfg/Praxxg9fMEzlG3i9sicMcfyCN0RUkRhpr wvq9mRJqHPRr87isRuEA2Z1VXYAfNuoS7jBSYrE/INWRj2LBLmZN7oUdGdRNvyRs8R1D 20cdd6z197iRj14CzhcfiJlVw7MgF0vwRDdFIduZi74IESUQVwE7Iv+DLCpLO7PGKPae 02RZfL1j40eWL5fNBlR8egTt9rkaqBCrwh0I8Zgt0jRK5EwhpawVLs3jhjRjgSXCkRCT ykN1iC9LxwOEoikBWdW0RA1cGtQ1isKz2ws10+fT80oRwLXq8u5lfton7qDKZx3ufxDJ 1I4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=R+b2huPMsaMi5FgkgPUWChaHItGkkPxr9G8EYuakqs4=; b=eqRHGE2Cqz6PSXtOD/3GdOmL2plKj2URR0zz8UbmA8+Mrk/SSI2Es9+GK1CbafveRE HJee8L23zGM31ytG2sL5Bx6yqcsGBH/BRLz4CLki7zJSqQmnimrBT95GzhlF/GekMr46 zhvRF6Uq8q+4iNV+j1Nsnytn1nicBuciRdR3QZJv6+0sjOzpwte1ow6KK6Mo43ZsTOiK drpQLb53EOJ5hAw2qJmMpiwf9xmSmOqEYjbaVLd60/Ta29phWfS9JM475RM4pUV2dJiV PgFBmBwsGtyak012po83jct8WoRtTnmEhj6f2yS43UGM6BhuYxdH2O7QHg72l9aapaXD 5r3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=taKgWB6h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p4-20020a637f44000000b0046b3ba2c806si22487564pgn.145.2022.10.22.01.33.42; Sat, 22 Oct 2022 01:33:58 -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=@linuxfoundation.org header.s=korg header.b=taKgWB6h; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233697AbiJVIUp (ORCPT + 99 others); Sat, 22 Oct 2022 04:20:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233723AbiJVITN (ORCPT ); Sat, 22 Oct 2022 04:19:13 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99FD82DF448; Sat, 22 Oct 2022 00:58:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2B633B80E4D; Sat, 22 Oct 2022 07:56:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8BD3CC433B5; Sat, 22 Oct 2022 07:56:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666425416; bh=tv9L0ATtm/g+3f1svrh0qKf6P+ZJy0hTBvk3G0cON/Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=taKgWB6he3HAjDBNzYi/l2yOdLSnNbrZi/Vcnw09X9OHZu5A+wsD12abKq8ULI2wN 9VHLqzHngDQKgRIfKod+I2f2J+NnSK2IwxsvGG0qNYSCLtzxU5dC27d67kVTok3hQd tUJz+2HbBCHZsb+5qnaNHBhG9IkG+vzilTm/4sqE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Bob Pearson , Li Zhijian , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.19 464/717] RDMA/rxe: Fix resize_finish() in rxe_queue.c Date: Sat, 22 Oct 2022 09:25:43 +0200 Message-Id: <20221022072518.828870179@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221022072415.034382448@linuxfoundation.org> References: <20221022072415.034382448@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747376027671324929?= X-GMAIL-MSGID: =?utf-8?q?1747376027671324929?= From: Bob Pearson [ Upstream commit fda5d0cf8aef12f0a4f714a96a4b2fce039a3e55 ] Currently in resize_finish() in rxe_queue.c there is a loop which copies the entries in the original queue into a newly allocated queue. The termination logic for this loop is incorrect. The call to queue_next_index() updates cons but has no effect on whether the queue is empty. So if the queue starts out empty nothing is copied but if it is not then the loop will run forever. This patch changes the loop to compare the value of cons to the original producer index. Fixes: ae6e843fe08d0 ("RDMA/rxe: Add memory barriers to kernel queues") Link: https://lore.kernel.org/r/20220825221446.6512-1-rpearsonhpe@gmail.com Signed-off-by: Bob Pearson Reviewed-by: Li Zhijian Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/sw/rxe/rxe_queue.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_queue.c b/drivers/infiniband/sw/rxe/rxe_queue.c index dbd4971039c0..d6dbf5a0058d 100644 --- a/drivers/infiniband/sw/rxe/rxe_queue.c +++ b/drivers/infiniband/sw/rxe/rxe_queue.c @@ -112,23 +112,25 @@ static int resize_finish(struct rxe_queue *q, struct rxe_queue *new_q, unsigned int num_elem) { enum queue_type type = q->type; + u32 new_prod; u32 prod; u32 cons; if (!queue_empty(q, q->type) && (num_elem < queue_count(q, type))) return -EINVAL; - prod = queue_get_producer(new_q, type); + new_prod = queue_get_producer(new_q, type); + prod = queue_get_producer(q, type); cons = queue_get_consumer(q, type); - while (!queue_empty(q, type)) { - memcpy(queue_addr_from_index(new_q, prod), + while ((prod - cons) & q->index_mask) { + memcpy(queue_addr_from_index(new_q, new_prod), queue_addr_from_index(q, cons), new_q->elem_size); - prod = queue_next_index(new_q, prod); + new_prod = queue_next_index(new_q, new_prod); cons = queue_next_index(q, cons); } - new_q->buf->producer_index = prod; + new_q->buf->producer_index = new_prod; q->buf->consumer_index = cons; /* update private index copies */