Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp228102pxx; Wed, 28 Oct 2020 03:26:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz7kZqtKg/zR3jUENbylXWQY+BNeCK0KWu5n9UyA3ZWB5PprpzZ/B2HGyOM8/xHRRHnPE4a X-Received: by 2002:a17:906:4a03:: with SMTP id w3mr6937371eju.15.1603880810977; Wed, 28 Oct 2020 03:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880810; cv=none; d=google.com; s=arc-20160816; b=n61KRinSc9+uRewjvt75n0iTSiIz9KUaquaNzlr+pp4hKQ6ujTBOVmfzWeTx4VECZ+ 3iY2fYn+CccVnmOLeGvOxE/2+g0W7v8lrMfyCuw/kGFvlGdiQfIG+YiDYxyf9EaBWR15 rut9vJqutv9wv0vzNu3iVTOy/qa+thh6/G4pf7n65+5VvfJ5zcLL4bgSZIq00+KFmh2u x8cWLWKv3rqrLHP7EJgXI+TU9ZO628xT0GWucd3GtlQm98WAJ237dU/H4PJ0AkhBgFuQ KfdiXuEAj7uJF+q4XcrM7H2nUPU/m1BjZMxZuvzwrvXHJJFmAb9LOJYM0ceoRwjRaScl nLuQ== 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=2YN7DCtKQ843NvSK6V4NJ2koHLQVF91OSA5kGTzWshs=; b=gqryKstZRfC2DAu9GOYbC5nCNfPkoRdiMJNBGjCx7fyVQ54Q3MIJTD5iY7FFO8/yLa joKqLVgjaL4fuSZNcCrvYrTk2S8a1F2f385UyBzXhfBAKQjKrwg8cyknrGvgTRynfXea bVVcNRLr42kn0rtKRzoxoCDoydevW+01sfDbGYX9VtwArfpD/x6wO5TvTJSQnZY15QWt dY+K4nBSRorR2w8l7AcI1Pa9xoBoXTYww1Ak6cf17W9HnLROrt/wKQZMVSdiE36Ia+Kr fQYNdlPkoe1UtCyr9pqTaTbsbqqbzJaj82CYzK6uS3S/uF6DWXCYATWqRmZsgGMpIwou a+NQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LFPXzRDA; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id lg14si2653130ejb.82.2020.10.28.03.26.28; Wed, 28 Oct 2020 03:26:50 -0700 (PDT) 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=@kernel.org header.s=default header.b=LFPXzRDA; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394027AbgJ0Okt (ORCPT + 99 others); Tue, 27 Oct 2020 10:40:49 -0400 Received: from mail.kernel.org ([198.145.29.99]:38976 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761428AbgJ0Ojl (ORCPT ); Tue, 27 Oct 2020 10:39:41 -0400 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0AC9E207BB; Tue, 27 Oct 2020 14:39:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809580; bh=czBi+i+yWR3U8R14MI2nOBnY/yIBtgjCkoed06usKzI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LFPXzRDAZkSkxqVIii6IPu3ZsbQc4K6c+2OeO3JaWxSJWtyK2XpJZUhkCSNv7obr0 GCbqDaQAPX8yyvYkBnMwXV8gp18vMq3lGPzweJULkPx2C2kc+elOUuUpERnwg3HNug 3fVDfskoGbDJbAT44CxVMP5lvA31GNvej14DJhr0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Leon Romanovsky , Shiraz Saleem , Jason Gunthorpe , Sasha Levin Subject: [PATCH 5.4 217/408] RDMA/umem: Prevent small pages from being returned by ib_umem_find_best_pgsz() Date: Tue, 27 Oct 2020 14:52:35 +0100 Message-Id: <20201027135505.160569924@linuxfoundation.org> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027135455.027547757@linuxfoundation.org> References: <20201027135455.027547757@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jason Gunthorpe [ Upstream commit 10c75ccb54e4fe548cb16d7ed426d7d709e6ae76 ] rdma_for_each_block() makes assumptions about how the SGL is constructed that don't work if the block size is below the page size used to to build the SGL. The rules for umem SGL construction require that the SG's all be PAGE_SIZE aligned and we don't encode the actual byte offset of the VA range inside the SGL using offset and length. So rdma_for_each_block() has no idea where the actual starting/ending point is to compute the first/last block boundary if the starting address should be within a SGL. Fixing the SGL construction turns out to be really hard, and will be the subject of other patches. For now block smaller pages. Fixes: 4a35339958f1 ("RDMA/umem: Add API to find best driver supported page size in an MR") Link: https://lore.kernel.org/r/2-v2-270386b7e60b+28f4-umem_1_jgg@nvidia.com Reviewed-by: Leon Romanovsky Reviewed-by: Shiraz Saleem Signed-off-by: Jason Gunthorpe Signed-off-by: Sasha Levin --- drivers/infiniband/core/umem.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 9be8f6c622db0..650f71dd4ab93 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -151,6 +151,12 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, dma_addr_t mask; int i; + /* rdma_for_each_block() has a bug if the page size is smaller than the + * page size used to build the umem. For now prevent smaller page sizes + * from being returned. + */ + pgsz_bitmap &= GENMASK(BITS_PER_LONG - 1, PAGE_SHIFT); + /* At minimum, drivers must support PAGE_SIZE or smaller */ if (WARN_ON(!(pgsz_bitmap & GENMASK(PAGE_SHIFT, 0)))) return 0; -- 2.25.1