Skip to content

Commit

Permalink
peer: drop support for PEEK
Browse files Browse the repository at this point in the history
We have no compelling usecase for PEEK support at the moment. Drop
it for now to allow us to simplify the logic quite a bit.

Receiving the same message several times (which PEEK allowed) has
counterintuitive semantics in particular due to different fd numbers
being used each time and due to the accounting of handles.

Signed-off-by: Tom Gundersen <teg@jklm.no>
  • Loading branch information
teg committed Mar 9, 2017
1 parent 733d7c0 commit 53daeb3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 46 deletions.
5 changes: 2 additions & 3 deletions include/uapi/linux/bus1.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ struct bus1_cmd_send {
} __attribute__((__aligned__(8)));

enum {
BUS1_RECV_FLAG_PEEK = 1ULL << 0,
BUS1_RECV_FLAG_SEED = 1ULL << 1,
BUS1_RECV_FLAG_INSTALL_FDS = 1ULL << 2,
BUS1_RECV_FLAG_SEED = 1ULL << 0,
BUS1_RECV_FLAG_INSTALL_FDS = 1ULL << 1,
};

enum {
Expand Down
17 changes: 4 additions & 13 deletions ipc/bus1/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,15 +470,13 @@ void bus1_message_stage(struct bus1_message *m, struct bus1_tx *tx)
*
* This installs the payload FDs and handles of @message into the receiving
* peer and the calling process. Handles are always installed, FDs are only
* installed if explicitly requested via @param.
* installed if explicitly requested via @inst_fds.
*
* Return: 0 on success, negative error code on failure.
*/
int bus1_message_install(struct bus1_message *m, struct bus1_cmd_recv *param)
int bus1_message_install(struct bus1_message *m, bool inst_fds)
{
size_t i, j, n, size, offset, n_handles = 0, n_fds = 0;
const bool inst_fds = param->flags & BUS1_RECV_FLAG_INSTALL_FDS;
const bool peek = param->flags & BUS1_RECV_FLAG_PEEK;
struct bus1_peer *peer = m->qnode.owner;
struct bus1_handle *h;
struct bus1_flist *e;
Expand Down Expand Up @@ -557,15 +555,8 @@ int bus1_message_install(struct bus1_message *m, struct bus1_cmd_recv *param)
}

/* charge resources */
if (peek) {
r = bus1_user_charge(&peer->user->limits.n_handles,
&peer->data.limits.n_handles, n_handles);
if (r < 0)
goto exit;
} else {
WARN_ON(n_handles < m->n_handles_charge);
m->n_handles_charge -= n_handles;
}
WARN_ON(n_handles < m->n_handles_charge);
m->n_handles_charge -= n_handles;

/* publish pool slice */
mutex_lock(&peer->data.lock);
Expand Down
2 changes: 1 addition & 1 deletion ipc/bus1/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ struct bus1_message *bus1_factory_instantiate(struct bus1_factory *f,

void bus1_message_free(struct kref *k);
void bus1_message_stage(struct bus1_message *m, struct bus1_tx *tx);
int bus1_message_install(struct bus1_message *m, struct bus1_cmd_recv *param);
int bus1_message_install(struct bus1_message *m, bool inst_fds);

/**
* bus1_message_ref() - acquire object reference
Expand Down
55 changes: 26 additions & 29 deletions ipc/bus1/peer.c
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,6 @@ static int bus1_peer_ioctl_send(struct bus1_peer *peer,
}

static struct bus1_queue_node *bus1_peer_peek(struct bus1_peer *peer,
struct bus1_cmd_recv *param,
bool *morep)
{
struct bus1_queue_node *qnode;
Expand All @@ -918,14 +917,6 @@ static struct bus1_queue_node *bus1_peer_peek(struct bus1_peer *peer,

lockdep_assert_held(&peer->local.lock);

if (unlikely(param->flags & BUS1_RECV_FLAG_SEED)) {
if (!peer->local.seed)
return ERR_PTR(-EAGAIN);

*morep = false;
return &peer->local.seed->qnode;
}

mutex_lock(&peer->data.lock);
while ((qnode = bus1_queue_peek(&peer->data.queue, morep))) {
switch (bus1_queue_node_get_type(qnode)) {
Expand Down Expand Up @@ -962,7 +953,7 @@ static struct bus1_queue_node *bus1_peer_peek(struct bus1_peer *peer,
continue;
}

if (!m && !(param->flags & BUS1_RECV_FLAG_PEEK))
if (!m)
bus1_queue_remove(&peer->data.queue, &peer->waitq,
qnode);

Expand All @@ -988,17 +979,25 @@ static int bus1_peer_ioctl_recv(struct bus1_peer *peer,

if (copy_from_user(&param, (void __user *)arg, sizeof(param)))
return -EFAULT;
if (unlikely(param.flags & ~(BUS1_RECV_FLAG_PEEK |
BUS1_RECV_FLAG_SEED |
if (unlikely(param.flags & ~(BUS1_RECV_FLAG_SEED |
BUS1_RECV_FLAG_INSTALL_FDS)))
return -EINVAL;

mutex_lock(&peer->local.lock);

qnode = bus1_peer_peek(peer, &param, &more);
if (IS_ERR(qnode)) {
r = PTR_ERR(qnode);
goto exit;
if (unlikely(param.flags & BUS1_RECV_FLAG_SEED)) {
if (!peer->local.seed) {
r = -EAGAIN;
goto exit;
}

qnode = &peer->local.seed->qnode;
} else {
qnode = bus1_peer_peek(peer, &more);
if (IS_ERR(qnode)) {
r = PTR_ERR(qnode);
goto exit;
}
}

type = bus1_queue_node_get_type(qnode);
Expand All @@ -1012,7 +1011,8 @@ static int bus1_peer_ioctl_recv(struct bus1_peer *peer,
goto exit;
}

r = bus1_message_install(m, &param);
r = bus1_message_install(m,
param.flags & BUS1_RECV_FLAG_INSTALL_FDS);
if (r < 0)
goto exit;

Expand All @@ -1024,17 +1024,15 @@ static int bus1_peer_ioctl_recv(struct bus1_peer *peer,
param.msg.n_handles = m->n_handles;
param.msg.n_fds = m->n_files;

if (likely(!(param.flags & BUS1_RECV_FLAG_PEEK))) {
if (unlikely(param.flags & BUS1_RECV_FLAG_SEED)) {
peer->local.seed = NULL;
} else {
mutex_lock(&peer->data.lock);
bus1_queue_remove(&peer->data.queue,
&peer->waitq, qnode);
mutex_unlock(&peer->data.lock);
}
bus1_message_unref(m);
if (unlikely(param.flags & BUS1_RECV_FLAG_SEED)) {
peer->local.seed = NULL;
} else {
mutex_lock(&peer->data.lock);
bus1_queue_remove(&peer->data.queue,
&peer->waitq, qnode);
mutex_unlock(&peer->data.lock);
}
bus1_message_unref(m);
break;
case BUS1_MSG_NODE_DESTROY:
case BUS1_MSG_NODE_RELEASE:
Expand All @@ -1049,8 +1047,7 @@ static int bus1_peer_ioctl_recv(struct bus1_peer *peer,
param.msg.n_handles = 0;
param.msg.n_fds = 0;

if (likely(!(param.flags & BUS1_RECV_FLAG_PEEK)))
bus1_handle_unref(h);
bus1_handle_unref(h);
break;
case BUS1_MSG_NONE:
default:
Expand Down

0 comments on commit 53daeb3

Please sign in to comment.