linux-rdma.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michal Kalderon <mkalderon@marvell.com>
To: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Ariel Elior <aelior@marvell.com>,
	"dledford@redhat.com" <dledford@redhat.com>,
	"bmt@zurich.ibm.com" <bmt@zurich.ibm.com>,
	"galpress@amazon.com" <galpress@amazon.com>,
	"sleybo@amazon.com" <sleybo@amazon.com>,
	"leon@kernel.org" <leon@kernel.org>,
	"linux-rdma@vger.kernel.org" <linux-rdma@vger.kernel.org>
Subject: RE: [EXT] Re: [PATCH v7 rdma-next 2/7] RDMA/core: Create mmap database and cookie helper functions
Date: Wed, 21 Aug 2019 17:14:38 +0000	[thread overview]
Message-ID: <CH2PR18MB3175EDB5640A3987D97A4DC0A1AA0@CH2PR18MB3175.namprd18.prod.outlook.com> (raw)
In-Reply-To: <20190821165121.GE8653@ziepe.ca>

> From: Jason Gunthorpe <jgg@ziepe.ca>
> Sent: Wednesday, August 21, 2019 7:51 PM
> 
> On Wed, Aug 21, 2019 at 04:47:47PM +0000, Michal Kalderon wrote:
> > > From: linux-rdma-owner@vger.kernel.org <linux-rdma-
> > > owner@vger.kernel.org> On Behalf Of Michal Kalderon
> > >
> > > > From: Jason Gunthorpe <jgg@ziepe.ca>
> > > > Sent: Tuesday, August 20, 2019 4:21 PM
> > > >
> > > > On Tue, Aug 20, 2019 at 03:18:42PM +0300, Michal Kalderon wrote:
> > > > > Create some common API's for adding entries to a xa_mmap.
> > > > > Searching for an entry and freeing one.
> > > > >
> > > > > +
> > > > > +/**
> > > > > + * rdma_user_mmap_entry_insert() - Allocate and insert an entry
> > > > > +to the
> > > > mmap_xa.
> > > > > + *
> > > > > + * @ucontext: associated user context.
> > > > > + * @obj: opaque driver object that will be stored in the entry.
> > > > > + * @address: The address that will be mmapped to the user
> > > > > + * @length: Length of the address that will be mmapped
> > > > > + * @mmap_flag: opaque driver flags related to the address (For
> > > > > + *           example could be used for cachability)
> > > > > + *
> > > > > + * This function should be called by drivers that use the
> > > > > +rdma_user_mmap
> > > > > + * interface for handling user mmapped addresses. The database
> > > > > +is handled in
> > > > > + * the core and helper functions are provided to insert entries
> > > > > +into the
> > > > > + * database and extract entries when the user call mmap with
> > > > > +the given
> > > > key.
> > > > > + * The function returns a unique key that should be provided to
> > > > > +user, the user
> > > > > + * will use the key to map the given address.
> > > > > + *
> > > > > + * Return: unique key or RDMA_USER_MMAP_INVALID if entry was
> > > > > +not
> > > > added.
> > > > > + */
> > > > > +u64 rdma_user_mmap_entry_insert(struct ib_ucontext *ucontext,
> > > > > +void
> > > > *obj,
> > > > > +				u64 address, u64 length, u8
> mmap_flag) {
> > > > > +	XA_STATE(xas, &ucontext->mmap_xa, 0);
> > > > > +	struct rdma_user_mmap_entry *entry;
> > > > > +	unsigned long index = 0, index_max;
> > > > > +	u32 xa_first, xa_last, npages;
> > > > > +	int err, i;
> > > > > +	void *ent;
> > > > > +
> > > > > +	entry = kzalloc(sizeof(*entry), GFP_KERNEL);
> > > > > +	if (!entry)
> > > > > +		return RDMA_USER_MMAP_INVALID;
> > > > > +
> > > > > +	entry->obj = obj;
> > > >
> > > > It is more a kernel pattern to have the driver allocate a
> > > > rdma_user_mmap_entry and extend it with its 'priv', then use
> > > > container_of
> > > then would we also want the driver to free the memory ?
> > > Or will it be ok to free it using the kref put callback ?
> >
> > Jason, I looked into this deeper today, it seems that since the Core
> > is the one handling the reference counting, and eventually Freeing the
> > object that it makes more sense to keep the allocation In core and not
> > in the drivers, since the driver won't be able to free The entry
> > without providing yet an additional callback function to the Core to
> > be called once the reference count reaches zero.
> 
> This already added a callback to free the xa_entry, why can't it free all the
> memory too when kref goes to 0?
True, could free it there. I just think we'll have a bit more duplication code
Between the drivers defining a very similar private structure and adding
Allocation calls before each of the rdma_user_mmap_insert function calls. 
 And just to make sure I follow, 
Do you mean creating the following structure per driver: 
Struct <driver>_user_mmap_entry {
	struct rdma_user_mmap_entry umap_entry;
              ... <private fields> ...
}

Thanks again, 
Michal

> 
> Jason

  reply	other threads:[~2019-08-21 17:14 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-20 12:18 [PATCH v7 rdma-next 0/7] RDMA/qedr: Use the doorbell overflow recovery mechanism for RDMA Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 1/7] RDMA/core: Move core content from ib_uverbs to ib_core Michal Kalderon
2019-08-20 12:58   ` Jason Gunthorpe
2019-08-20 21:30     ` Michal Kalderon
2019-08-21 16:30       ` Michal Kalderon
2019-08-20 14:08   ` Gal Pressman
2019-08-20 21:32     ` Michal Kalderon
2019-08-21  6:06       ` Gal Pressman
2019-08-21  7:56         ` Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 2/7] RDMA/core: Create mmap database and cookie helper functions Michal Kalderon
2019-08-20 13:21   ` Jason Gunthorpe
2019-08-20 21:23     ` [EXT] " Michal Kalderon
2019-08-21 16:47       ` Michal Kalderon
2019-08-21 16:51         ` Jason Gunthorpe
2019-08-21 17:14           ` Michal Kalderon [this message]
2019-08-21 17:37             ` Jason Gunthorpe
2019-08-26 11:53               ` Michal Kalderon
2019-08-26 12:01                 ` Gal Pressman
2019-08-22  8:35   ` Gal Pressman
2019-08-25  8:36     ` Michal Kalderon
2019-08-25 10:39       ` Gal Pressman
2019-08-26  8:41         ` Michal Kalderon
2019-08-26 15:30       ` Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 3/7] RDMA/efa: Use the common mmap_xa helpers Michal Kalderon
2019-08-22 13:18   ` Gal Pressman
2019-08-25  8:41     ` Michal Kalderon
2019-08-25 10:45       ` Gal Pressman
2019-08-26  8:42         ` Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 4/7] RDMA/siw: " Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 5/7] RDMA/qedr: Use the common mmap API Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 6/7] RDMA/qedr: Add doorbell overflow recovery support Michal Kalderon
2019-08-20 12:18 ` [PATCH v7 rdma-next 7/7] RDMA/qedr: Add iWARP doorbell " Michal Kalderon
2019-08-20 18:31 ` [PATCH v7 rdma-next 0/7] RDMA/qedr: Use the doorbell overflow recovery mechanism for RDMA Gal Pressman
2019-08-21  8:03   ` Michal Kalderon
2019-08-21 10:15     ` Gal Pressman
2019-08-21 10:32       ` Michal Kalderon
2019-08-21 10:41         ` Gal Pressman
2019-08-21 12:25           ` Gal Pressman
2019-08-21 16:23             ` Gal Pressman
2019-08-21 16:27               ` Michal Kalderon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CH2PR18MB3175EDB5640A3987D97A4DC0A1AA0@CH2PR18MB3175.namprd18.prod.outlook.com \
    --to=mkalderon@marvell.com \
    --cc=aelior@marvell.com \
    --cc=bmt@zurich.ibm.com \
    --cc=dledford@redhat.com \
    --cc=galpress@amazon.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    --cc=sleybo@amazon.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).