libkrunfw icon indicating copy to clipboard operation
libkrunfw copied to clipboard

Socket starvation issue

Open justxuewei opened this issue 9 months ago • 2 comments

In the tsi_accept function, we must release the lock before tsi_accept_inet or tsi_accept_vsock. Otherwise, starvation might occur.

For example, in a thread, call accept() to block and wait for a connection to arrive. At this time, the lock of sock is acquired by the tsi_accept method. Then, in another thread, we are trying to call any syscall, e.g. shutdown(). If no connection comes, the shutdown() never gets a chance to acquire the lock.

I believe that, apart from tsi_accept(), all functions that call another function which might block the operation share this issue.

void tsi_accept() {
    lock_sock(sk);
    // omitted
    release_sock(sk);
    // a possible function to block the operation
    tsi_accept_inet();
    lock_sock(sk);
    // omitted
    release_sock(sk);
}

@slp Please take a look at this issue. Thanks!

justxuewei avatar Mar 03 '25 06:03 justxuewei

I think you're right, @justxuewei, thanks for pointing it out.

This week I'm going to spin out a patch series and send it as an RFC to the LKML. I'll try to address this issue, but also it'll give us a nicer platform to review TSI and discuss other potential problems. I'll put you in CC.

slp avatar Mar 04 '25 10:03 slp

Cool! It's great for me

justxuewei avatar Mar 04 '25 10:03 justxuewei