Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp528526rdb; Thu, 8 Feb 2024 12:57:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IEd2mc+P87TSw/BMXW1rDbbLkPhLA+fCNum1c2xc2MyvJO7ZrOcQuKNXXAgL6UcpNhm/4Mx X-Received: by 2002:a05:6870:3281:b0:219:7981:30c0 with SMTP id q1-20020a056870328100b00219798130c0mr749101oac.19.1707425830681; Thu, 08 Feb 2024 12:57:10 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707425830; cv=pass; d=google.com; s=arc-20160816; b=LY2vlvMQMi3r9d8AIuMFwtCuBojUscE7G6pgfal9xjYCYug9wm8G6s8CeeQO8NaXAc x48T7Tz+BUll80PGiAEBtN5SLcTUcx8zNjPnwxNvAT4GYlCgIMGaZdmbYn86hDmtDQLN JYe5ZW6ZO7saBpgreJsYfMj7ElEvyBVSL+2L2ochb5iYCrSZIQP0e8Kva2T1sHu/Sth5 0eMCkjGV6OlOJkoKNNmT9OaZCcGBgbqlBnz8GTPugP6r8zMDu7aTktTeEt38998ydKjB rPJ/KmlKSRQkVDeafshl89UjlZaevvT7JKf6/s0ks2t2sMz1zBAmOaAgazoBzkjJKFJp rsVQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=h8E10FDOpzIm5efl0mA2CAXdhkpGX2Vqi/2VCns5LkQ=; fh=qBn2J8l1E3jpI4zsdXYeMYLEefD/iZ/yBE+kX8uyNv0=; b=wTIExtUtpmZLWS7B/DdUdxjtTA24IECMmpcN4gkwMyXJoIwuyzVHOkba3yqivr1K94 XzA9j6sZ6/qpIBT0hc8vCVs+aJsJLRvpP5nZ6A0YCOwVHVK1VYyqRrnergTOmIVx7Wvn Zf22hB8b3wPWpuzTpfxDcma+DZ6pIcYEkf6qGbofk5MKvxORIClNPiZbiqe5DoaZTQ5o so6kfgyhqxyDgfdWHxKAdgepSiJvamWUeBMLC4gWCjE/SLDJp64LC7KYhvvp9AxJVwZQ V8BUuxYW56QC2dlM37ffvAKGAdE3ExW5aS4C1fLvmfBdboBmj7DJdhNpRAZvvU8nO7Qm KRdQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=XjAIgW0Y; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-58655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58655-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXJeIV4lL1Y+NkZOeSryA19YlspsBFD33I/dje8VXrjg4VtzHo2lV6+NwUqREW04SEWTJUe+0DqZDf9skIXKvG3gFaSO7kOCFDwP3uO4Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id cl5-20020a056a02098500b005bd27be66e1si404721pgb.719.2024.02.08.12.57.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 12:57:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=XjAIgW0Y; arc=pass (i=1 spf=pass spfdomain=ziepe.ca dkim=pass dkdomain=ziepe.ca); spf=pass (google.com: domain of linux-kernel+bounces-58655-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58655-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 5E1ECB2DE16 for ; Thu, 8 Feb 2024 20:18:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7087338DEF; Thu, 8 Feb 2024 20:16:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="XjAIgW0Y" Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E568A3839C for ; Thu, 8 Feb 2024 20:16:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707423403; cv=none; b=XDWPveuf1IazSGWveXmnkb8y44X/fXfb5c14SoMG1noTfWzGP6ACWv8e65tOoUYkCVz3oUMT4Ll/Lmf7dXtdk0gZo9k169UGGGNDTnePlRZltv1+NkREJfKqccjD4rDg/zqPBISwToi/BH8VScEIXoiclnHXjDXIsnfeuEEYcsk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707423403; c=relaxed/simple; bh=flHsUzAN1b+v0w8PvGBjhwVSZ3GxquBnNsjj8HFsyAE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BG6j8JW6PbgyY1Kge7HFIFvJ419FUhSjk0BOLZxIkeidmfdfNdcTXkqcP7bZTfevMMX2Cg+7zgn7xm1L/Iwhmz8djMmdwtxfaSEpjksR3jBxrK6Rff0/PgxC0mOSWG6Mq9u9SfWlJ580qL6K8MMYaMYaQcdy6NXPg66ZkcId/Zs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca; spf=pass smtp.mailfrom=ziepe.ca; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b=XjAIgW0Y; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=ziepe.ca Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ziepe.ca Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3bff5e9ccdeso62138b6e.3 for ; Thu, 08 Feb 2024 12:16:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; t=1707423401; x=1708028201; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=h8E10FDOpzIm5efl0mA2CAXdhkpGX2Vqi/2VCns5LkQ=; b=XjAIgW0YnUCBJ2RazjHePnx33WK/v2HoD5SM/bdyzw1NDZg12yX39qjcDbcJcTdMuF OwDytEtyDE5IMfkWRd+2f66dB08rSbWgYAefnAWcgRefj0UPG1zU78COjG2/vzz9sPZf /pHkvZOlvhtrgJ39zOhIKOBjwHlumZh///VPd2UZbM1fcXPHtB2aku4KfzY3QPeYXmFI yNxFbO6Ra9GAijhZMrjipHBX1ztrXvyzcMwAwCqEtGY747dO/hrZCGBpLwdDUtHEQ03z V8EljbluGjg9Vr/dKTpdJOGRVPfB5aFq+bu1JDoDHvU6FlPn86QpAFcVkNMu2eTlsFF0 uixw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707423401; x=1708028201; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=h8E10FDOpzIm5efl0mA2CAXdhkpGX2Vqi/2VCns5LkQ=; b=OWsF9Q/Q51jLg3Y7xDAgUMq0TnKWKuLGJFSNfqDybumO2EF2Y1belAEQl/WnO+h7lt EoM7P8GRbdEGMV4/7/3uq95mwQZ4+B48FGW0XjFifGUxKfg5MsaV3sTDvZozqJiJfnxt l2Qpx6k7sOPJqDS/rrA1z9LzYuELyz9aiXFKORHIAhUpbTSawfobyNjJjibo3QxRZ5h3 iL3ExmDBQTa1v/BvpcGNWpcjFDiU4dn5TltOCWutO4aw6veHFUuoTEa0gikM83Ub6tf2 i4mUEWcwDYe1HYQfk6YPVldqVizNggFT+9V8NMZ1HrQoZ2Rw928TyqRXUwFzBFD8mqYW ZN6A== X-Gm-Message-State: AOJu0Yyv+cRraSHVnrV3Ic6akNLfAkS8OeKehGd3cvztGZePlxjH9tD1 o26sEJH5nOHFUVX5YoEeHel5/zUxsCed7szENphsVXVAcbFkE8WJHpfDtllWZhU= X-Received: by 2002:a05:6808:2e8c:b0:3bd:36fc:1c1e with SMTP id gt12-20020a0568082e8c00b003bd36fc1c1emr673830oib.44.1707423400843; Thu, 08 Feb 2024 12:16:40 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXIrODRyJcaN5pdqZBtOjmf2iFFQUJa2vBW2Jn+j9PQuQBTyzXAHfDo6M+CJICY6m0fWttc9YwoH+40lDg/E3ibTXAbeZZXkTmm8HMcgdAfSkf6GapjHtBcVEHKtNOuPOj/VIqKK6C6+Qo1YOiyntjobxxy8QqGXUVd6mM+2f6Lr3gsBUw1oDd9ULOddvUtjOoGT1E9YVjdn7zJbAVl/m4rpcx73WSnOqE/XWPtO6JaM8dl Received: from ziepe.ca (hlfxns017vw-142-68-80-239.dhcp-dynamic.fibreop.ns.bellaliant.net. [142.68.80.239]) by smtp.gmail.com with ESMTPSA id dz2-20020a056808438200b003bff074dd43sm14449oib.58.2024.02.08.12.16.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 12:16:39 -0800 (PST) Received: from jgg by wakko with local (Exim 4.95) (envelope-from ) id 1rYAp5-00FyMn-0D; Thu, 08 Feb 2024 16:16:39 -0400 Date: Thu, 8 Feb 2024 16:16:38 -0400 From: Jason Gunthorpe To: Konstantin Taranov Cc: Long Li , Konstantin Taranov , "sharmaajay@microsoft.com" , "leon@kernel.org" , "linux-rdma@vger.kernel.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH rdma-next v1 1/1] RDMA/mana_ib: Fix bug in creation of dma regions Message-ID: <20240208201638.GZ31743@ziepe.ca> References: <1707318566-3141-1-git-send-email-kotaranov@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Thu, Feb 08, 2024 at 06:53:05PM +0000, Konstantin Taranov wrote: > > From: Long Li > > Sent: Thursday, 8 February 2024 19:43 > > To: Konstantin Taranov ; Konstantin > > Taranov ; sharmaajay@microsoft.com; > > jgg@ziepe.ca; leon@kernel.org > > Cc: linux-rdma@vger.kernel.org; linux-kernel@vger.kernel.org > > Subject: RE: [PATCH rdma-next v1 1/1] RDMA/mana_ib: Fix bug in creation of > > dma regions > > > > > > > > /* Hardware requires dma region to align to chosen page size */ > > > - page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, 0); > > > + page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, virt); > > > if (!page_sz) { > > > ibdev_dbg(&dev->ib_dev, "failed to find page size.\n"); > > > return -ENOMEM; > > > } > > > > How about doing: > > page_sz = ib_umem_find_best_pgsz(umem, PAGE_SZ_BM, force_zero_offset > > ? 0 : virt); > > > > Will this work? This can get rid of the following while loop. > > > > I do not think so. I mentioned once, that it was failing for me with existing code > with the 4K-aligned addresses and 8K pages. In this case, we miscalculate the > number of pages. So, we think that it is one 8K page, but it is in fact two. That is a confusing statement.. What is "we" here? ib_umem_dma_offset() is not always guaranteed to be zero, with a 0 iova. With higher order pages the offset can be within the page, it generates offset = IOVA % pgsz There are a couple places that do want the offset to be fixed to zero and have the loop, at this point it would be good to consolidate them into some common ib_umem_find_best_pgsz_zero_offset() or something. > > > + > > > + if (force_zero_offset) { > > > + while (ib_umem_dma_offset(umem, page_sz) && page_sz > > > > PAGE_SIZE) > > > + page_sz /= 2; > > > + if (ib_umem_dma_offset(umem, page_sz) != 0) { > > > + ibdev_dbg(&dev->ib_dev, "failed to find page size to > > > force zero offset.\n"); > > > + return -ENOMEM; > > > + } > > > + } > > > + Yes this doesn't look quite right.. It should flow from the HW capability, the helper you call should be tightly linked to what the HW can do. ib_umem_find_best_pgsz() is used for MRs that have the usual offset = IOVA % pgsz We've always created other helpers for other restrictions. So you should move your "force_zero_offset" into another helper and describe exactly how the HW works to support the calculation It is odd to have the offset loop and be using ib_umem_find_best_pgsz() with some iova, usually you'd use ib_umem_find_best_pgoff() in those cases, see the other callers. Jason