Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5321296imm; Tue, 18 Sep 2018 07:46:36 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaYDosaS84zGkaSUJTteI3IhO4wYjVybiuW6P8ea2JmRYNhhziB4ESb8l8fhALXLtG3ZX83 X-Received: by 2002:a62:9f85:: with SMTP id v5-v6mr31179027pfk.27.1537281996087; Tue, 18 Sep 2018 07:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537281996; cv=none; d=google.com; s=arc-20160816; b=mzkURQUPXuT/EoQVia8AKvY3i2KLyb7BrtS2cul5vX9e0ivteYs+Ep0gnrjxfBvFKT 8nrJ/h6MMs0AvmF5cyxvqZ3Lltw3pAut8sdHuKYmcSDHHmxxpHwWhDHD1GYw7oCB79cS /qtcFxRXOxeWdoxTR96OkVzKfbJibohhUcVdSPMF7N6/Ltx8B3ipNSBU0cCk5xfz7gQ0 4EHdl3RbV4PmjL3iuEazFvwbEyd2HnC0g35O+QIWAP/4sH38bloo1kmHTh6jLcfmLGhR 2hUyRGjZByvmapLfh7BqVP0L/xXL/DsMNlxw9D5AuNl1fh0B9bgXcKvqbIavYNUdRIW7 0j5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ehvIOQwcYh0xz5/c8Mj9f/Ezb2VwaoXPACqtKlUQPF0=; b=clr5vX0bNHluz3Ws5xw30Tad3D9yNah/jMlLsH36sX/ns/r/WOiqZbH7J906735DsN dxueUti8SfaODjj68jPpzJ98YdqPOzzS+NQpSTUp4va68ocaKNGyn00qC3J5vqlYrAPA BIDzmodiSjHlBun7Lbj31Imc2UfDZpVkjCpRJlvBGFVlAtEFzNC5yP5N334z0l2QmLI3 68CnEwQPXWUgyMx/eX04gFFpkaZoCX7+HH1b5tt6X3U6ok2L7vT9bBriXsRN3VN4hM09 YJ9icmd+3xejgcZ6SZKveDsHjEUWdsmgMdeRRpjw2+QONY6k6Reai97ZxeIWjGaHbuH0 rPCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=G4Qu44wd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1-v6si19168250plo.96.2018.09.18.07.46.20; Tue, 18 Sep 2018 07:46:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ziepe.ca header.s=google header.b=G4Qu44wd; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729618AbeIRURk (ORCPT + 99 others); Tue, 18 Sep 2018 16:17:40 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:54571 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728631AbeIRURj (ORCPT ); Tue, 18 Sep 2018 16:17:39 -0400 Received: by mail-it0-f66.google.com with SMTP id f14-v6so3544426ita.4 for ; Tue, 18 Sep 2018 07:44:44 -0700 (PDT) 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:user-agent; bh=ehvIOQwcYh0xz5/c8Mj9f/Ezb2VwaoXPACqtKlUQPF0=; b=G4Qu44wdIG7vGHEBOhI82KXEiJjteLFYuKwW82bgohhGDRnbwkBVziB4ExSWallzSq cBgkPjnTtlkUC+P7cA1PKaCb432ay5SrQGpzpzURh6mJ242yipIv4e+yH6Qqn0eZu4KR tzeHE1OmYv8XDQLXZL7bUqpHLp6KZzxE1D1p7J9mqhmjDWrVabKniH8UU2WSqAVKF5ze vtNNjRIXIzwo1oKjF3S1jDW8RlvTBTgSEnyu5ClWNhZXYDNfRyppOcdkmWJMMgNZSGRQ SNA2B5wu5bTy4uwTaJmj3Bd89/Asm5e7Me4BhzDtB1GZdGCieNrKuL4s+o2tOTK2Dk31 NouQ== 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:user-agent; bh=ehvIOQwcYh0xz5/c8Mj9f/Ezb2VwaoXPACqtKlUQPF0=; b=NPBY9YgMZ6YbABfNJgaBk0egicVkJQ/Fx/wzIYC8IZmEOVVObFqJbEEGmHFh6qs+jr a16hQAIqU8ejtOW0evVR+IdmtlPeC894uiR3kij1KNAJ2MA+STO4/Zvi0gQR3cLxe69f KbvzKzWl6yIfNVy6rNLsODZz34BRWE0BPr1G/99b7liu5nlIiqMULHGpyAVnegRxlGb/ auW8plQKCS0IBTA64OwxiPg0C5XVFQZEEs6MEYYkXm6pTmclYB3QBdH//bVKcsJZbuWE uflT+CHyjay9o7u4WS03SYDp2MNzlqeRyu7l0CSyn7MpDsQNZxu38enXP8S3+pbecb8k uzrQ== X-Gm-Message-State: APzg51DskYGRcZmSH8K1G+47Wl6p1p4KHQrrZ8CCmxCTczWCSu37dM/+ waku41GhcTaFWD9oTfg8ZAgS8g== X-Received: by 2002:a24:fe44:: with SMTP id w65-v6mr16103999ith.122.1537281884320; Tue, 18 Sep 2018 07:44:44 -0700 (PDT) Received: from ziepe.ca (S010614cc2056d97f.ed.shawcable.net. [174.3.196.123]) by smtp.gmail.com with ESMTPSA id a11-v6sm4501587ita.21.2018.09.18.07.44.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 18 Sep 2018 07:44:42 -0700 (PDT) Received: from jgg by mlx.ziepe.ca with local (Exim 4.90_1) (envelope-from ) id 1g2HF3-0003Pn-Bi; Tue, 18 Sep 2018 08:44:41 -0600 Date: Tue, 18 Sep 2018 08:44:41 -0600 From: Jason Gunthorpe To: Jan Dakinevich Cc: Doug Ledford , Yishai Hadas , Leon Romanovsky , Parav Pandit , Mark Bloch , Daniel Jurgens , Kees Cook , Kamal Heib , Bart Van Assche , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Denis Lunev , Konstantin Khorenko Subject: Re: [PATCH 1/4] IB/core: introduce ->release() callback Message-ID: <20180918144441.GH11367@ziepe.ca> References: <1537275826-27247-1-git-send-email-jan.dakinevich@virtuozzo.com> <1537275826-27247-2-git-send-email-jan.dakinevich@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1537275826-27247-2-git-send-email-jan.dakinevich@virtuozzo.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 18, 2018 at 04:03:43PM +0300, Jan Dakinevich wrote: > IB infrastructure shares common device instance constructor with > reference counting, and it uses kzalloc() to allocate memory > for device specific instance with incapsulated ib_device field as one > contigous memory block. > > The issue is that the device specific instances tend to be too large > and require high page order memory allocation. Unfortunately, kzalloc() > in ib_alloc_device() can not be replaced with kvzalloc() since it would > require a lot of review in all IB driver to prove correctness of the > replacement. > > The driver can allocate some heavy partes of their instance for itself > and keep pointers for them in own instance. For this it is important > that the alocated parts have the same life time as ib_device, thus > their deallocation should be based on the same reference counting. > > Let suppose: > > struct foo_ib_device { > struct ib_device device; > > void *part; > > ... > }; > > To properly free memory from .foo_ib_part the driver should provide > function for ->release() callback: > > void foo_ib_release(struct ib_device *device) > { > struct foo_ib_device *foo = container_of(device, struct foo_ib_device, > device); > > kvfree(foo->part); > } > > ...and initialiaze this callback immediately after foo_ib_device > instance allocation. > > struct foo_ib_device *foo; > > foo = ib_alloc_device(sizeof(struct foo_ib_device)); > > foo->device.release = foo_ib_release; > > /* allocate parts */ > foo->part = kvmalloc(65536, GFP_KERNEL); > > Signed-off-by: Jan Dakinevich > drivers/infiniband/core/device.c | 2 ++ > include/rdma/ib_verbs.h | 2 ++ > 2 files changed, 4 insertions(+) > > diff --git a/drivers/infiniband/core/device.c b/drivers/infiniband/core/device.c > index db3b627..a8c8b0d 100644 > +++ b/drivers/infiniband/core/device.c > @@ -215,6 +215,8 @@ static void ib_device_release(struct device *device) > ib_cache_release_one(dev); > kfree(dev->port_immutable); > } > + if (dev->release) > + dev->release(dev); > kfree(dev); > } Nope, the driver module could be unloaded at this point. The driver should free memory after its call to ib_unregister_device returns. Jason