Skip to content

Commit bec68fa

Browse files
Kent Overstreetbcrl
authored andcommitted
aio: io_cancel() no longer returns the io_event
Originally, io_event() was documented to return the io_event if cancellation succeeded - the io_event wouldn't be delivered via the ring buffer like it normally would. But this isn't what the implementation was actually doing; the only driver implementing cancellation, the usb gadget code, never returned an io_event in its cancel function. And aio_complete() was recently changed to no longer suppress event delivery if the kiocb had been cancelled. This gets rid of the unused io_event argument to kiocb_cancel() and kiocb->ki_cancel(), and changes io_cancel() to return -EINPROGRESS if kiocb->ki_cancel() returned success. Also tweak the refcounting in kiocb_cancel() to make more sense. Signed-off-by: Kent Overstreet <koverstreet@google.com> Cc: Zach Brown <zab@redhat.com> Cc: Felipe Balbi <balbi@ti.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Mark Fasheh <mfasheh@suse.com> Cc: Joel Becker <jlbec@evilplan.org> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Jens Axboe <axboe@kernel.dk> Cc: Asai Thambi S P <asamymuthupa@micron.com> Cc: Selvan Mani <smani@micron.com> Cc: Sam Bradshaw <sbradshaw@micron.com> Cc: Jeff Moyer <jmoyer@redhat.com> Cc: Al Viro <viro@zeniv.linux.org.uk> Cc: Benjamin LaHaise <bcrl@kvack.org> Signed-off-by: Benjamin LaHaise <bcrl@kvack.org>
1 parent 723be6e commit bec68fa

3 files changed

Lines changed: 12 additions & 33 deletions

File tree

‎drivers/usb/gadget/inode.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ struct kiocb_priv {
524524
unsigned actual;
525525
};
526526

527-
static int ep_aio_cancel(struct kiocb *iocb, struct io_event *e)
527+
static int ep_aio_cancel(struct kiocb *iocb)
528528
{
529529
struct kiocb_priv *priv = iocb->private;
530530
struct ep_data *epdata;
@@ -540,7 +540,6 @@ static int ep_aio_cancel(struct kiocb *iocb, struct io_event *e)
540540
// spin_unlock(&epdata->dev->lock);
541541
local_irq_enable();
542542

543-
aio_put_req(iocb);
544543
return value;
545544
}
546545

‎fs/aio.c‎

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,7 @@ void kiocb_set_cancel_fn(struct kiocb *req, kiocb_cancel_fn *cancel)
358358
}
359359
EXPORT_SYMBOL(kiocb_set_cancel_fn);
360360

361-
static int kiocb_cancel(struct kioctx *ctx, struct kiocb *kiocb,
362-
struct io_event *res)
361+
static int kiocb_cancel(struct kioctx *ctx, struct kiocb *kiocb)
363362
{
364363
kiocb_cancel_fn *old, *cancel;
365364
int ret = -EINVAL;
@@ -381,12 +380,10 @@ static int kiocb_cancel(struct kioctx *ctx, struct kiocb *kiocb,
381380
atomic_inc(&kiocb->ki_users);
382381
spin_unlock_irq(&ctx->ctx_lock);
383382

384-
memset(res, 0, sizeof(*res));
385-
res->obj = (u64)(unsigned long)kiocb->ki_obj.user;
386-
res->data = kiocb->ki_user_data;
387-
ret = cancel(kiocb, res);
383+
ret = cancel(kiocb);
388384

389385
spin_lock_irq(&ctx->ctx_lock);
386+
aio_put_req(kiocb);
390387

391388
return ret;
392389
}
@@ -408,7 +405,6 @@ static void free_ioctx(struct work_struct *work)
408405
{
409406
struct kioctx *ctx = container_of(work, struct kioctx, free_work);
410407
struct aio_ring *ring;
411-
struct io_event res;
412408
struct kiocb *req;
413409
unsigned cpu, head, avail;
414410

@@ -419,7 +415,7 @@ static void free_ioctx(struct work_struct *work)
419415
struct kiocb, ki_list);
420416

421417
list_del_init(&req->ki_list);
422-
kiocb_cancel(ctx, req, &res);
418+
kiocb_cancel(ctx, req);
423419
}
424420

425421
spin_unlock_irq(&ctx->ctx_lock);
@@ -795,21 +791,6 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
795791
spin_unlock_irqrestore(&ctx->ctx_lock, flags);
796792
}
797793

798-
/*
799-
* cancelled requests don't get events, userland was given one
800-
* when the event got cancelled.
801-
*/
802-
if (unlikely(xchg(&iocb->ki_cancel,
803-
KIOCB_CANCELLED) == KIOCB_CANCELLED)) {
804-
/*
805-
* Can't use the percpu reqs_available here - could race with
806-
* free_ioctx()
807-
*/
808-
atomic_inc(&ctx->reqs_available);
809-
/* Still need the wake_up in case free_ioctx is waiting */
810-
goto put_rq;
811-
}
812-
813794
/*
814795
* Add a completion event to the ring buffer. Must be done holding
815796
* ctx->completion_lock to prevent other code from messing with the tail
@@ -862,7 +843,6 @@ void aio_complete(struct kiocb *iocb, long res, long res2)
862843
if (iocb->ki_eventfd != NULL)
863844
eventfd_signal(iocb->ki_eventfd, 1);
864845

865-
put_rq:
866846
/* everything turned out well, dispose of the aiocb. */
867847
aio_put_req(iocb);
868848

@@ -1439,7 +1419,6 @@ static struct kiocb *lookup_kiocb(struct kioctx *ctx, struct iocb __user *iocb,
14391419
SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb,
14401420
struct io_event __user *, result)
14411421
{
1442-
struct io_event res;
14431422
struct kioctx *ctx;
14441423
struct kiocb *kiocb;
14451424
u32 key;
@@ -1457,18 +1436,19 @@ SYSCALL_DEFINE3(io_cancel, aio_context_t, ctx_id, struct iocb __user *, iocb,
14571436

14581437
kiocb = lookup_kiocb(ctx, iocb, key);
14591438
if (kiocb)
1460-
ret = kiocb_cancel(ctx, kiocb, &res);
1439+
ret = kiocb_cancel(ctx, kiocb);
14611440
else
14621441
ret = -EINVAL;
14631442

14641443
spin_unlock_irq(&ctx->ctx_lock);
14651444

14661445
if (!ret) {
1467-
/* Cancellation succeeded -- copy the result
1468-
* into the user's buffer.
1446+
/*
1447+
* The result argument is no longer used - the io_event is
1448+
* always delivered via the ring buffer. -EINPROGRESS indicates
1449+
* cancellation is progress:
14691450
*/
1470-
if (copy_to_user(result, &res, sizeof(res)))
1471-
ret = -EFAULT;
1451+
ret = -EINPROGRESS;
14721452
}
14731453

14741454
percpu_ref_put(&ctx->users);

‎include/linux/aio.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct kiocb;
2727
*/
2828
#define KIOCB_CANCELLED ((void *) (~0ULL))
2929

30-
typedef int (kiocb_cancel_fn)(struct kiocb *, struct io_event *);
30+
typedef int (kiocb_cancel_fn)(struct kiocb *);
3131

3232
struct kiocb {
3333
atomic_t ki_users;

0 commit comments

Comments
 (0)