From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04822C388F7 for ; Fri, 13 Nov 2020 12:49:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 915C120A8B for ; Fri, 13 Nov 2020 12:49:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ziepe.ca header.i=@ziepe.ca header.b="oQ2LazpM" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726308AbgKMMtK (ORCPT ); Fri, 13 Nov 2020 07:49:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726279AbgKMMtJ (ORCPT ); Fri, 13 Nov 2020 07:49:09 -0500 Received: from mail-qv1-xf44.google.com (mail-qv1-xf44.google.com [IPv6:2607:f8b0:4864:20::f44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8589C0613D1 for ; Fri, 13 Nov 2020 04:49:09 -0800 (PST) Received: by mail-qv1-xf44.google.com with SMTP id g19so4495754qvy.2 for ; Fri, 13 Nov 2020 04:49:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ziepe.ca; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=RcvJ0ZjeSv/YgPQ0Qoap3goR6x+DGLtXOMsSJfrBjSk=; b=oQ2LazpMrvjAQvcBZ9lE0E4g7PuQt+LQvg0yLMauHeuqSBAhJJCcP7ZyvGsFLxjQ64 IpjAuezncv+uVVvPG57vG5ST+ZLoLQKA2cYObEzfME5bQqWsie/91wjK1jBU2ygh+GNR 3q6yYFAC2NkspnFZi0/jzc+/HRnOLj1hwIUxpR62OdJJDpOBjRE3AUO3vJdkf6LHtkBQ aPWk6DxQhJKLNvbDMOuVC73cpB89RfKQVcT2VIa8POExfzWPctvgGNr8jAQH6ephc2O+ oLSJmnsP6WSmg39cRR6U8PEN0+8pjnDSAb4qsm93v3T7ysMxhAkqauP0yWCYoWXF3dlb 8+QA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=RcvJ0ZjeSv/YgPQ0Qoap3goR6x+DGLtXOMsSJfrBjSk=; b=kPcl+5e7rm5fDSHHHwmnSJk7UZiTDcmM0OT5cjyHD5poRGm4yFQ8jK74UKTpNH2Z6+ JpE4i7Pc7SM1clXzoD8xVkaL4tNVgFyLfbcDDkxjTT+UPeLJp9fJS2sYVYDWAAXE35RM xqGZMApwzkRY7nDcwoqGiimjlVsK427A/A6qXQui2HDjJL9hNomNv73YpSa7ouuIP72a ar+jtmzRW3aeE0ux6HgNak8V/QEtiX/Hl3yTrKG5xGrNr4LWbkACWSLWTZopjUeHMlmT Q1wSByFZr2ncM3KQ4uW6QfZKmvtr1jwWwf5pyeobuydzzkcwbxReO382D9OkCW9w3eXB J2qg== X-Gm-Message-State: AOAM531JY/fP0Iprbl+saEw/VXWJ6bUjGoIzQ4ahGSzbg2cfch2z+uUE edtqBK72zZzDfj6V/uFmyxpm0Q== X-Google-Smtp-Source: ABdhPJwIF8ycppZSd+rISqHYM9BvW9DZmk6aIDyfXSgiNUIrCa8Gmbax0jo6QmVC6Wi7QqOX+U1DaQ== X-Received: by 2002:a0c:ecc1:: with SMTP id o1mr2010711qvq.6.1605271748507; Fri, 13 Nov 2020 04:49:08 -0800 (PST) Received: from ziepe.ca (hlfxns017vw-156-34-48-30.dhcp-dynamic.fibreop.ns.bellaliant.net. [156.34.48.30]) by smtp.gmail.com with ESMTPSA id s134sm6952212qke.99.2020.11.13.04.49.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Nov 2020 04:49:07 -0800 (PST) Received: from jgg by mlx with local (Exim 4.94) (envelope-from ) id 1kdYVm-004PIv-Vu; Fri, 13 Nov 2020 08:49:07 -0400 Date: Fri, 13 Nov 2020 08:49:06 -0400 From: Jason Gunthorpe To: "Xiong, Jianxin" Cc: "linux-rdma@vger.kernel.org" , "dri-devel@lists.freedesktop.org" , Doug Ledford , Leon Romanovsky , Sumit Semwal , Christian Koenig , "Vetter, Daniel" Subject: Re: [PATCH v10 1/6] RDMA/umem: Support importing dma-buf as user memory region Message-ID: <20201113124906.GC244516@ziepe.ca> References: <1605044477-51833-1-git-send-email-jianxin.xiong@intel.com> <1605044477-51833-2-git-send-email-jianxin.xiong@intel.com> <20201113003037.GY244516@ziepe.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org On Fri, Nov 13, 2020 at 03:30:04AM +0000, Xiong, Jianxin wrote: > > From: Jason Gunthorpe > > Sent: Thursday, November 12, 2020 4:31 PM > > To: Xiong, Jianxin > > Cc: linux-rdma@vger.kernel.org; dri-devel@lists.freedesktop.org; Doug Ledford ; Leon Romanovsky > > ; Sumit Semwal ; Christian Koenig ; Vetter, Daniel > > > > Subject: Re: [PATCH v10 1/6] RDMA/umem: Support importing dma-buf as user memory region > > > > On Tue, Nov 10, 2020 at 01:41:12PM -0800, Jianxin Xiong wrote: > > > +struct ib_umem *ib_umem_dmabuf_get(struct ib_device *device, > > > + unsigned long offset, size_t size, > > > + int fd, int access, > > > + const struct dma_buf_attach_ops *ops) { > > > + struct dma_buf *dmabuf; > > > + struct ib_umem_dmabuf *umem_dmabuf; > > > + struct ib_umem *umem; > > > + unsigned long end; > > > + long ret; > > > + > > > + if (check_add_overflow(offset, (unsigned long)size, &end)) > > > + return ERR_PTR(-EINVAL); > > > + > > > + if (unlikely(PAGE_ALIGN(end) < PAGE_SIZE)) > > > + return ERR_PTR(-EINVAL); > > > > This is weird, what does it do? > > This sequence is modeled after the following code from ib_umem_init_odp(): > > if (check_add_overflow(umem_odp->umem.address, > (unsigned long)umem_odp->umem.length, > &end)) > return -EOVERFLOW; > end = ALIGN(end, page_size); > if (unlikely(end < page_size)) > return -EOVERFLOW; > > The weird part seems to be checking if 'end' is 0, but that should have been covered > by check_add_overflow() already. I think the + if (unlikely(!ib_umem_num_pages(umem))) { Catches the same condition, no need to do it twice Jason