From patchwork Fri Feb 3 19:43:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Gardner X-Patchwork-Id: 1737229 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=canonical.com header.i=@canonical.com header.a=rsa-sha256 header.s=20210705 header.b=MS/0M7t9; dkim-atps=neutral Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4P7mMw5ynBz23hd for ; Sat, 4 Feb 2023 06:45:15 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1pO1zY-0004eJ-S4; Fri, 03 Feb 2023 19:45:00 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by huckleberry.canonical.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1pO1zX-0004dx-0A for kernel-team@lists.ubuntu.com; Fri, 03 Feb 2023 19:44:59 +0000 Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-1.canonical.com (Postfix) with ESMTPS id 8A9214166C for ; Fri, 3 Feb 2023 19:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1675453498; bh=Z0/e51KFDtwHnTiMsCg1/SaVbV81iC88/mBNkXJNAVk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=MS/0M7t9f5pNxHVnF6o8HjKl02JEjp4Wlct8OLbKHf9jg+nsn6/iXRhzrFIYQy3PG FQKhvQLvmTd9EZCYkc0nCrvge/AhYXr0mbAWmxVggeblQiMyHXP9d1zi40OT3W2N/i PJGwoVdhOq2iPXHWdeIJ53f49RSsnsIxhHA94K6vxKz5Z9xt/RMVz96YgqIL/NXoa1 bY7SYaMzczghUmYsb1WFqppFTlx051l6esGHieassUzvPTIsejXBuyh4VnDxaagJsc /IDFixayDsEUaLAQ4jw/PmjxvDud6jbL8fkiwGKSwpecLC1S4QFGpl+p/0cLIbk8FZ vZS+hsDKSniXw== Received: by mail-pl1-f198.google.com with SMTP id u6-20020a170903124600b00188cd4769bcso2983489plh.0 for ; Fri, 03 Feb 2023 11:44:58 -0800 (PST) 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:message-id:reply-to; bh=Z0/e51KFDtwHnTiMsCg1/SaVbV81iC88/mBNkXJNAVk=; b=GuoyWqvv8/i6ZTa0ECgkaCEswgoh3USRFxs5XwWpsE8UYphKk4N5iZBxHtSFt9BmZ4 /79l5fdxP2/lKr8ZKc5dqTo7LX9g9pe843ddaiETshGWLACtz9OZy0Rzkt9lBwLrDDbd NBrJ2CuSCbAWXypBEkFCOQjHZRDi72hNXz2snrq6UZIDD6rFPQ7rsj6uRAt5k8KXwEl3 X5CMIGNcBE1XZcLtAuGNvPrDY3OqKVtWu9gUzKg3QA5DkjHRJksV1nWqA+kOjOfjSXJA GznI0Qa8B9qfLazRpeAsZlaEtJNg1Ve9s6hcVmNnjcdxm3JOpv5V1OvrLTiIHBHSaijW 2sMQ== X-Gm-Message-State: AO0yUKXruyFDgBAcnnlCwRFmo/d8NOdmpkXxUmqWqO12/mm8A5y2FBjg +8KCqisBUytY8TKoAXW0KrMrBIfgXFFm57KMas35FbsQlKulK2tCSDmDuoFlSnlwqkiWqdo4MgR z6ObYBI3uaELaIUUr/+7jLycmBeXJGiiTsR3+OJldSw== X-Received: by 2002:a05:6a00:882:b0:58d:987b:2e9 with SMTP id q2-20020a056a00088200b0058d987b02e9mr16179147pfj.24.1675453496501; Fri, 03 Feb 2023 11:44:56 -0800 (PST) X-Google-Smtp-Source: AK7set9O+RlzRy5QZHeTXaitUcPfc/QDR7fRq9oExFAKvAG0TqthHql6BZ0KM6Bpu9sr2L/25pDHNA== X-Received: by 2002:a05:6a00:882:b0:58d:987b:2e9 with SMTP id q2-20020a056a00088200b0058d987b02e9mr16179127pfj.24.1675453496221; Fri, 03 Feb 2023 11:44:56 -0800 (PST) Received: from localhost.localdomain ([69.163.84.166]) by smtp.gmail.com with ESMTPSA id o185-20020a62cdc2000000b005815017d348sm2254538pfg.179.2023.02.03.11.44.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 11:44:55 -0800 (PST) From: Tim Gardner To: kernel-team@lists.ubuntu.com Subject: [PATCH] RDMA/core: Fix ib block iterator counter overflow Date: Fri, 3 Feb 2023 12:43:36 -0700 Message-Id: <20230203194336.341786-2-tim.gardner@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203194336.341786-1-tim.gardner@canonical.com> References: <20230203194336.341786-1-tim.gardner@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Yonatan Nachum BugLink: https://bugs.launchpad.net/bugs/2004807 When registering a new DMA MR after selecting the best aligned page size for it, we iterate over the given sglist to split each entry to smaller, aligned to the selected page size, DMA blocks. In given circumstances where the sg entry and page size fit certain sizes and the sg entry is not aligned to the selected page size, the total size of the aligned pages we need to cover the sg entry is >= 4GB. Under this circumstances, while iterating page aligned blocks, the counter responsible for counting how much we advanced from the start of the sg entry is overflowed because its type is u32 and we pass 4GB in size. This can lead to an infinite loop inside the iterator function because the overflow prevents the counter to be larger than the size of the sg entry. Fix the presented problem by changing the advancement condition to eliminate overflow. Backtrace: [ 192.374329] efa_reg_user_mr_dmabuf [ 192.376783] efa_register_mr [ 192.382579] pgsz_bitmap 0xfffff000 rounddown 0x80000000 [ 192.386423] pg_sz [0x80000000] umem_length[0xc0000000] [ 192.392657] start 0x0 length 0xc0000000 params.page_shift 31 params.page_num 3 [ 192.399559] hp_cnt[3], pages_in_hp[524288] [ 192.403690] umem->sgt_append.sgt.nents[1] [ 192.407905] number entries: [1], pg_bit: [31] [ 192.411397] biter->__sg_nents [1] biter->__sg [0000000008b0c5d8] [ 192.415601] biter->__sg_advance [665837568] sg_dma_len[3221225472] [ 192.419823] biter->__sg_nents [1] biter->__sg [0000000008b0c5d8] [ 192.423976] biter->__sg_advance [2813321216] sg_dma_len[3221225472] [ 192.428243] biter->__sg_nents [1] biter->__sg [0000000008b0c5d8] [ 192.432397] biter->__sg_advance [665837568] sg_dma_len[3221225472] Fixes: a808273a495c ("RDMA/verbs: Add a DMA iterator to return aligned contiguous memory blocks") Signed-off-by: Yonatan Nachum Link: https://lore.kernel.org/r/20230109133711.13678-1-ynachum@amazon.com Signed-off-by: Leon Romanovsky (cherry picked from commit 0afec5e9cea732cb47014655685a2a47fb180c31) Signed-off-by: Tim Gardner Acked-by: Ian May --- drivers/infiniband/core/verbs.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/verbs.c b/drivers/infiniband/core/verbs.c index f8964c8cf0ad..8f2f0b8fb37a 100644 --- a/drivers/infiniband/core/verbs.c +++ b/drivers/infiniband/core/verbs.c @@ -2957,15 +2957,18 @@ EXPORT_SYMBOL(__rdma_block_iter_start); bool __rdma_block_iter_next(struct ib_block_iter *biter) { unsigned int block_offset; + unsigned int sg_delta; if (!biter->__sg_nents || !biter->__sg) return false; biter->__dma_addr = sg_dma_address(biter->__sg) + biter->__sg_advance; block_offset = biter->__dma_addr & (BIT_ULL(biter->__pg_bit) - 1); - biter->__sg_advance += BIT_ULL(biter->__pg_bit) - block_offset; + sg_delta = BIT_ULL(biter->__pg_bit) - block_offset; - if (biter->__sg_advance >= sg_dma_len(biter->__sg)) { + if (sg_dma_len(biter->__sg) - biter->__sg_advance > sg_delta) { + biter->__sg_advance += sg_delta; + } else { biter->__sg_advance = 0; biter->__sg = sg_next(biter->__sg); biter->__sg_nents--;