Commit f9ae3204 authored by Hannes Reinecke's avatar Hannes Reinecke Committed by Jakub Kicinski
Browse files

net/tls: split tls_rx_reader_lock



Split tls_rx_reader_{lock,unlock} into an 'acquire/release' and
the actual locking part.
With that we can use the tls_rx_reader_lock in situations where
the socket is already locked.

Suggested-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarJakub Kicinski <kuba@kernel.org>
Link: https://lore.kernel.org/r/20230726191556.41714-6-hare@suse.de


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 11863c6d
Loading
Loading
Loading
Loading
+22 −16
Original line number Diff line number Diff line
@@ -1848,13 +1848,10 @@ tls_read_flush_backlog(struct sock *sk, struct tls_prot_info *prot,
	return sk_flush_backlog(sk);
}

static int tls_rx_reader_lock(struct sock *sk, struct tls_sw_context_rx *ctx,
static int tls_rx_reader_acquire(struct sock *sk, struct tls_sw_context_rx *ctx,
				 bool nonblock)
{
	long timeo;
	int err;

	lock_sock(sk);

	timeo = sock_rcvtimeo(sk, nonblock);

@@ -1868,26 +1865,30 @@ static int tls_rx_reader_lock(struct sock *sk, struct tls_sw_context_rx *ctx,
			      !READ_ONCE(ctx->reader_present), &wait);
		remove_wait_queue(&ctx->wq, &wait);

		if (timeo <= 0) {
			err = -EAGAIN;
			goto err_unlock;
		}
		if (signal_pending(current)) {
			err = sock_intr_errno(timeo);
			goto err_unlock;
		}
		if (timeo <= 0)
			return -EAGAIN;
		if (signal_pending(current))
			return sock_intr_errno(timeo);
	}

	WRITE_ONCE(ctx->reader_present, 1);

	return 0;
}

static int tls_rx_reader_lock(struct sock *sk, struct tls_sw_context_rx *ctx,
			      bool nonblock)
{
	int err;

err_unlock:
	lock_sock(sk);
	err = tls_rx_reader_acquire(sk, ctx, nonblock);
	if (err)
		release_sock(sk);
	return err;
}

static void tls_rx_reader_unlock(struct sock *sk, struct tls_sw_context_rx *ctx)
static void tls_rx_reader_release(struct sock *sk, struct tls_sw_context_rx *ctx)
{
	if (unlikely(ctx->reader_contended)) {
		if (wq_has_sleeper(&ctx->wq))
@@ -1899,6 +1900,11 @@ static void tls_rx_reader_unlock(struct sock *sk, struct tls_sw_context_rx *ctx)
	}

	WRITE_ONCE(ctx->reader_present, 0);
}

static void tls_rx_reader_unlock(struct sock *sk, struct tls_sw_context_rx *ctx)
{
	tls_rx_reader_release(sk, ctx);
	release_sock(sk);
}