Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp227616pxx; Wed, 28 Oct 2020 03:25:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTgfKxPeUUukyyid0kh1/9N03jB9cdidJDwFvJFCmmeh6M0Jx4QenhQPVjJScQcdmnp50D X-Received: by 2002:a17:906:3997:: with SMTP id h23mr6595605eje.191.1603880758857; Wed, 28 Oct 2020 03:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603880758; cv=none; d=google.com; s=arc-20160816; b=HVVXz6gaSz1mHsOZFpd81iK180lLZjS5mfaSBdDWAnK28JNKdRgvg2o359fArhWh1x 2Vv5abnTLB2ZYA2WQjuDIkD6hyW8n/HJq/49bOlsRt2QB/EQcCSgSyvUkc1i3pgU4Da7 w3jX1ErbxXBEOx01aDHVOgfHwE5H22gSPAEdyR9kI9BNwJSOrnD2ZNCL8xAV2oXidsw8 iIkKK0RuBdvUHjGNqjOuYzr/HLknvOIBSjOswJMLeLPluWKhJc0lPAH4fevWEofAXm3k mb8ZOxR7TyRQ5J6NgdY74iVsfOgIovdHk4lQpkCyKdjMQeCPmx+pCPX9SnGq+1lzTElB u/Ww== 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=MxWmxKFtBHYN72CG8p/ST5nlsfy61uXUpasgGV0Aohw=; b=XN+eLHkZYfpIadaeKo6C6G9qLHgrGDd5+ET2YRmwnDXwosXUbhdUiQSlqXdzA+RYq5 y4f9Z3S3ND+zyqYkxy4JcpAYl0Bo5vjAOgTIlUM1GuekoP9sgTBWlRjCMuzIOZrV7NGk KwTO9KathqOXQ1jbl742sbgSn040kKDGhHuXZggD1SHUDfLoUpjWlYd/o5lmpX+Zl2Lp m6zZr4h8TwOWQAVqBNAaFd8jm2GcUQr+gO5QtlVSePDEWcqZ2hJXrth00nic1xVUc3Sc Gez2eKOtc6/7GUDCMXc3Wyjq5t+J1O8a7I2j/kUQLHXrdifS/LJDBZ6rzJr1DOUCHXM+ pkcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=xxNNCa6k; 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 t1si2868715ejb.712.2020.10.28.03.25.36; Wed, 28 Oct 2020 03:25:58 -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=xxNNCa6k; 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 S1761443AbgJ0Ojq (ORCPT + 99 others); Tue, 27 Oct 2020 10:39:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:38830 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761407AbgJ0Ojd (ORCPT ); Tue, 27 Oct 2020 10:39:33 -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 58F72206B2; Tue, 27 Oct 2020 14:39:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1603809571; bh=p7Ao6xwiYPhTOoUygIuMFHW2Bq6Zrcv+vD1LUZqNAy0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=xxNNCa6kZlmda2p7OL7W4quIqsgzQ2yxwof8ZH6JQIMgH50sde/w6eBUbSyxK56/b xcEIV+L3j0bIMz2llFFD6uRGosvzx2Pb7fSJ/xShLGrNMX9skbeF0HhFCRpnjsfPIm xZYxaDtMcfyEvl6gHUMQ2Ipgqfa98wBIhn0PwtQc= 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 216/408] RDMA/umem: Fix ib_umem_find_best_pgsz() for mappings that cross a page boundary Date: Tue, 27 Oct 2020 14:52:34 +0100 Message-Id: <20201027135505.113316605@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 a40c20dabdf9045270767c75918feb67f0727c89 ] It is possible for a single SGL to span an aligned boundary, eg if the SGL is 61440 -> 90112 Then the length is 28672, which currently limits the block size to 32k. With a 32k page size the two covering blocks will be: 32768->65536 and 65536->98304 However, the correct answer is a 128K block size which will span the whole 28672 bytes in a single block. Instead of limiting based on length figure out which high IOVA bits don't change between the start and end addresses. That is the highest useful page size. Fixes: 4a35339958f1 ("RDMA/umem: Add API to find best driver supported page size in an MR") Link: https://lore.kernel.org/r/1-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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/core/umem.c b/drivers/infiniband/core/umem.c index 0d42ba8c0b696..9be8f6c622db0 100644 --- a/drivers/infiniband/core/umem.c +++ b/drivers/infiniband/core/umem.c @@ -156,8 +156,13 @@ unsigned long ib_umem_find_best_pgsz(struct ib_umem *umem, return 0; va = virt; - /* max page size not to exceed MR length */ - mask = roundup_pow_of_two(umem->length); + /* The best result is the smallest page size that results in the minimum + * number of required pages. Compute the largest page size that could + * work based on VA address bits that don't change. + */ + mask = pgsz_bitmap & + GENMASK(BITS_PER_LONG - 1, + bits_per((umem->length - 1 + virt) ^ virt)); /* offset into first SGL */ pgoff = umem->address & ~PAGE_MASK; -- 2.25.1