From: Jason Gunthorpe <jgunthorpe-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
To: Matan Barak <matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Doug Ledford <dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>,
Sean Hefty <sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>,
Tal Alon <talal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Liran Liss <liranl-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Haggai Eran <haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Majd Dibbiny <majd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>,
Christoph Lameter <cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org>,
Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Subject: Re: [RFC ABI V1 7/8] RDMA/core: Change locking of ib_uobject
Date: Wed, 13 Jul 2016 11:16:57 -0600 [thread overview]
Message-ID: <20160713171657.GB19657@obsidianresearch.com> (raw)
In-Reply-To: <1467293971-25688-8-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
On Thu, Jun 30, 2016 at 04:39:30PM +0300, Matan Barak wrote:
> This patch presents some concept about lockless scheme. It's only
> intended to open discussion and still misses some crucial parts.
It isn't really lockless, is it? I gather the intent is to remove the
per-uobj lock(s) and replace with a ucontext rwsem?
> Every ib_uobject has a usecnt atomic variable. Single rwsem in
> ib_uverbs_file (protect destruction of device from execution of
> commands).
>
> For every command execution:
> a. Check if device is available (as of today, with srcu)
> b. Take down_read(&file->close_sem)
> c. <User is now protected from closing the process and ib-dev
> destruction>
> d. When an object is used -> use uverbs_lock_object function
> implemented in this patch.
> i .If the object isn't available (-EBUSY)
I'd like to see a detailed list of all the calls that change from
blocking to EBUSY with this approach.
I also think this should be stand-alone as part of the uobject rework
series.. Again it seems like this benifits any approach.
uverbs_lock_object is in an different patch in the series..
I'm always nervous when I see people create their own locks with
atomics. Don't do that. That is a rw lock using try_lock.
> e. Unlock with uverbs_unlock_object (implemented in this patch)
> f. Release up_read(&file->close_sem)
g. release srcu
If the close_sem is always being held, then I suspect we can drop SRCU
as well??
> ib_uobjects are lockless. If two commands are executed in
> parallel and one need exclusive access (WRITE/DESTROY) -> one
> command will fail. User-space needs to either synchronize or do
> something productive with the failure.
I think this can work for destroy, but I have a hard time seeing how
it is going to be OK for WRITE/MODIFY/etc operations.
eg rereg_mr holds the write lock, I'm not sure I'm comfortable seeing
that be allowed to fail ..
> @@ -308,8 +298,8 @@ ssize_t ib_uverbs_alloc_pd(struct ib_uverbs_file *file,
> if (!uobj)
> return -ENOMEM;
>
> - init_uobj(uobj, 0, file->ucontext, &pd_lock_class);
> - down_write(&uobj->mutex);
> + down_read(&file->close_sem);
> + init_uobj(uobj, 0, file->ucontext);
Seeing this pattern in your patches really makes me wonder.. What is
the down_write even doing at that point???
uobj = kmalloc(sizeof *uobj, GFP_KERNEL);
init_uobj(uobj, 0, file->ucontext, &pd_lock_class);
down_write(&uobj->mutex);
init_uobj doesn't add the memory to any lists or anything. How could
another thread get access to the pointer and contend on the mutex?
I guess it is because later we do:
ret = idr_add_uobj(&ib_uverbs_pd_idr, uobj);
While holding the lock. But that is a really ugly API. Nothing should be
added to the idr until it is 100% initialized, so we don't need
concurrency protection. What is the write lock doing at that point??
This whole flow should be simplified, which will make the locking
requirements a lot clearer.
uobj = uobj_alloc(file->ucontext, 0, sizeof(*uobj));
[.. full setup ..]
uobj_activate(uobj); // live = 1, list_add_tail, idr_add
resp.handle = uobj->id;
copy_to_user(..);
put_uobj(uobj);
return ret;
err1:
uobj_deactivate(uobj);
err2:
put_obj(uobj);
I would do the above sort of restructuring as another (mergable, even)
patch, then rip out the locking.
Also, I think the destruction should be equally cleaned up. If you
introduce a patch with actual ops and a destroy function pointer
per-type then a centralized destruct call can be implemented that does
the correct lock, wrapping the functionc all. Again this would be a
nice clean up to have distinct from the ioctl stuff...
Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-07-13 17:16 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-30 13:39 [RFC ABI V1 0/8] SG-based RDMA ABI Proposal Matan Barak
[not found] ` <1467293971-25688-1-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-06-30 13:39 ` [RFC ABI V1 1/8] RDMA/core: Export RDMA IOCTL declarations Matan Barak
[not found] ` <1467293971-25688-2-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-12 19:12 ` Jason Gunthorpe
[not found] ` <20160712191256.GA8206-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-12 19:43 ` Leon Romanovsky
2016-06-30 13:39 ` [RFC ABI V1 2/8] RDMA/core: Move uobject code to separate files Matan Barak
[not found] ` <1467293971-25688-3-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-12 19:15 ` Jason Gunthorpe
[not found] ` <20160712191507.GB8206-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-12 19:38 ` Leon Romanovsky
2016-07-13 14:34 ` Matan Barak
2016-06-30 13:39 ` [RFC ABI V1 3/8] RDMA/core: Refactor IDR to be per-device Matan Barak
[not found] ` <1467293971-25688-4-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-12 19:29 ` Jason Gunthorpe
[not found] ` <20160712192933.GD8206-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-12 19:48 ` Leon Romanovsky
2016-06-30 13:39 ` [RFC ABI V1 4/8] RDMA/core: Add support for custom types Matan Barak
[not found] ` <1467293971-25688-5-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-12 19:23 ` Jason Gunthorpe
[not found] ` <20160712192345.GC8206-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-13 14:44 ` Matan Barak
[not found] ` <081a02c0-0650-d0c2-494c-19a64b83cbc1-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-13 16:39 ` Jason Gunthorpe
[not found] ` <20160713163924.GA19657-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-13 16:57 ` Matan Barak
[not found] ` <0959d391-75fb-75e8-ef2e-9d8c06b1b96f-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-13 17:21 ` Jason Gunthorpe
[not found] ` <20160713172116.GC19657-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-14 5:30 ` Matan Barak
[not found] ` <5fdae959-5ab2-ee17-e36e-3642ddd3e6ce-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-14 16:41 ` Jason Gunthorpe
[not found] ` <20160714164121.GA2046-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-19 14:05 ` Matan Barak
[not found] ` <a1fcb1a7-0028-329a-d34a-ca8b52323916-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-19 20:36 ` Jason Gunthorpe
[not found] ` <20160719203609.GD16042-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-20 8:01 ` Matan Barak
[not found] ` <9727f6e6-47fd-fb0a-537f-6264e8d742a9-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-20 17:49 ` Jason Gunthorpe
2016-07-14 6:30 ` Leon Romanovsky
2016-06-30 13:39 ` [RFC ABI V1 5/8] RDMA/core: Introduce add/remove uobj from types Matan Barak
2016-06-30 13:39 ` [RFC ABI V1 6/8] RDMA/core: Add new ioctl interface Matan Barak
2016-06-30 13:39 ` [RFC ABI V1 7/8] RDMA/core: Change locking of ib_uobject Matan Barak
[not found] ` <1467293971-25688-8-git-send-email-matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-13 17:16 ` Jason Gunthorpe [this message]
[not found] ` <20160713171657.GB19657-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-14 7:59 ` Matan Barak
[not found] ` <6ae1a553-408c-723a-93a2-3d46d952ce35-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-14 17:00 ` Jason Gunthorpe
[not found] ` <20160714170051.GB2046-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-19 15:16 ` Matan Barak
[not found] ` <b47386f4-fdb5-d24b-dbc6-9b5e18be6bf9-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-19 20:44 ` Jason Gunthorpe
[not found] ` <20160719204456.GF16042-ePGOBjL8dl3ta4EC/59zMFaTQe2KTcn/@public.gmane.org>
2016-07-20 7:54 ` Matan Barak (External)
[not found] ` <5c6e6a5d-9fde-a31f-1038-dce9e09662c4-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2016-07-20 17:56 ` Jason Gunthorpe
2016-06-30 13:39 ` [RFC ABI V1 8/8] RDMA/{hw, core}: Provide simple skeleton to IOCTL interface Matan Barak
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=20160713171657.GB19657@obsidianresearch.com \
--to=jgunthorpe-epgobjl8dl3ta4ec/59zmfatqe2ktcn/@public.gmane.org \
--cc=cl-vYTEC60ixJUAvxtiuMwx3w@public.gmane.org \
--cc=dledford-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org \
--cc=haggaie-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=leonro-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=linux-rdma-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=liranl-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=majd-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=matanb-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
--cc=sean.hefty-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
--cc=talal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org \
/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).