Re: [RFC PATCH v2] can: isotp: add module parameter for maximum pdu size

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 22.03.23 09:56, Marc Kleine-Budde wrote:
On 20.03.2023 22:07:56, Oliver Hartkopp wrote:


Why are you allocating the max_pdu_size, not rx.len?

There is one upper limit which is selected when the 8300 bytes (99,9% of
isotp use-cases) are not enough.

I intentionally did not want to handle re-allocations for every increase of
received PDU size on this socket.

Just for simplicity reasons.

Hmmm. The worst case would be ~1MiB of contiguous kernel memory used, if
a 8301 bytes message would be send. That puts a lot of pressure on the
kernel memory for IMHO no good reason.

No, that's not the plan.

The max_pdu_size is a module parameter that simplifies the process, when someone needs unusually long PDUs without changing the static buffer size in the kernel code.

When you have the use-case to transfer PDUs with 128 kByte you would set the max_pdu_size to 128 kByte.

If you need 8301 bytes you set it to 8301.

It is very likely that only one or two isotp socket instances would ever allocate this extended buffer on one system at one time.

All other isotp sockets stay with the static buffer of 8300 bytes.

This patch is also taken if the kmalloc() fails, right?

s/patch/path/ ?!

doh!

Yes. At the end even the extended buffer might be too small. And when we
don't have enough space - either with our without kmalloc() - it throws and
error.

For that reason a failed kmalloc() does not create any stress. We just stay
on the default buffer.

Just out of interest: How does ISOTP handle this situation? Is an error
message forwarded to the sender?

   		/* send FC frame with overflow status */
   		isotp_send_fc(sk, ae, ISOTP_FC_OVFLW);

Yes. As you can see here the receiver sends and "overflow" error message to the sender, when the receive buffer can not handle the PDU size announced in the "first frame" of the PDU transmission.

The PDU transmission failure is therefore detected by the sender.

This is also implemented on the sender side where the flow control with ISOTP_FC_OVFLW leads to -EMSGSIZE as return value

https://elixir.bootlin.com/linux/v6.2/source/net/can/isotp.c#L419


I've been thinking about some sendfile() implementation too. But this again
would bloat the code and would not solve the rx side.

I'm not talking about sendfile. Have a look at j1939's
j1939_sk_send_loop();

| https://elixir.bootlin.com/linux/v6.2/source/net/can/j1939/socket.c#L1114


This does not work for isotp like this as you have to handle different block sizes in the flow control message.

what about: ARRAY_SIZE(so->rx.sbuf)


Looks good. I was just unsure which macro to use ;-)

You can also use sizeof(so->rx.sbuf).

ARRAY_SIZE would cause a compile error if you convert so->rx.sbuf to a
pointer to dynamically allocated mem, while sizeof() still compiles.

so->rx.sbuf is always a static buffer.

Only so->rx.buf can point to either so->rx.sbuf or to a dynamically allocated memory.

But when sizeof() is always safe it would take this for the v3 patch.

Best regards,
Oliver



+	so->tx.buflen = DEFAULT_MAX_PDU_SIZE;
+

here too. This would use the DEFAULT_MAX_PDU_SIZE at one single point. No
chance to get these values out of sync.

ACK

Marc




[Index of Archives]     [Automotive Discussions]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]     [CAN Bus]

  Powered by Linux