Skip to content

Commit

Permalink
tls: use fixed size for tls_offload_context_{tx,rx}.driver_state
Browse files Browse the repository at this point in the history
driver_state is a flex array, but is always allocated by the tls core
to a fixed size (TLS_DRIVER_STATE_SIZE_{TX,RX}). Simplify the code by
making that size explicit so that sizeof(struct
tls_offload_context_{tx,rx}) works.

Signed-off-by: Sabrina Dubroca <sd@queasysnail.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Sabrina Dubroca authored and David S. Miller committed Oct 13, 2023
1 parent 0700aa3 commit 9f0c824
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
14 changes: 4 additions & 10 deletions include/net/tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ struct tls_record_info {
skb_frag_t frags[MAX_SKB_FRAGS];
};

#define TLS_DRIVER_STATE_SIZE_TX 16
struct tls_offload_context_tx {
struct crypto_aead *aead_send;
spinlock_t lock; /* protects records list */
Expand All @@ -163,17 +164,13 @@ struct tls_offload_context_tx {
void (*sk_destruct)(struct sock *sk);
struct work_struct destruct_work;
struct tls_context *ctx;
u8 driver_state[] __aligned(8);
/* The TLS layer reserves room for driver specific state
* Currently the belief is that there is not enough
* driver specific state to justify another layer of indirection
*/
#define TLS_DRIVER_STATE_SIZE_TX 16
u8 driver_state[TLS_DRIVER_STATE_SIZE_TX] __aligned(8);
};

#define TLS_OFFLOAD_CONTEXT_SIZE_TX \
(sizeof(struct tls_offload_context_tx) + TLS_DRIVER_STATE_SIZE_TX)

enum tls_context_flags {
/* tls_device_down was called after the netdev went down, device state
* was released, and kTLS works in software, even though rx_conf is
Expand Down Expand Up @@ -303,6 +300,7 @@ struct tls_offload_resync_async {
u32 log[TLS_DEVICE_RESYNC_ASYNC_LOGMAX];
};

#define TLS_DRIVER_STATE_SIZE_RX 8
struct tls_offload_context_rx {
/* sw must be the first member of tls_offload_context_rx */
struct tls_sw_context_rx sw;
Expand All @@ -326,17 +324,13 @@ struct tls_offload_context_rx {
struct tls_offload_resync_async *resync_async;
};
};
u8 driver_state[] __aligned(8);
/* The TLS layer reserves room for driver specific state
* Currently the belief is that there is not enough
* driver specific state to justify another layer of indirection
*/
#define TLS_DRIVER_STATE_SIZE_RX 8
u8 driver_state[TLS_DRIVER_STATE_SIZE_RX] __aligned(8);
};

#define TLS_OFFLOAD_CONTEXT_SIZE_RX \
(sizeof(struct tls_offload_context_rx) + TLS_DRIVER_STATE_SIZE_RX)

struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,
u32 seq, u64 *p_record_sn);

Expand Down
4 changes: 2 additions & 2 deletions net/tls/tls_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,7 +1038,7 @@ static struct tls_offload_context_tx *alloc_offload_ctx_tx(struct tls_context *c
struct tls_offload_context_tx *offload_ctx;
__be64 rcd_sn;

offload_ctx = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_TX, GFP_KERNEL);
offload_ctx = kzalloc(sizeof(*offload_ctx), GFP_KERNEL);
if (!offload_ctx)
return NULL;

Expand Down Expand Up @@ -1225,7 +1225,7 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx)
goto release_lock;
}

context = kzalloc(TLS_OFFLOAD_CONTEXT_SIZE_RX, GFP_KERNEL);
context = kzalloc(sizeof(*context), GFP_KERNEL);
if (!context) {
rc = -ENOMEM;
goto release_lock;
Expand Down

0 comments on commit 9f0c824

Please sign in to comment.