From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7CEA6C433EF for ; Wed, 16 Mar 2022 03:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343716AbiCPD0T (ORCPT ); Tue, 15 Mar 2022 23:26:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244144AbiCPD0S (ORCPT ); Tue, 15 Mar 2022 23:26:18 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF94ABEA; Tue, 15 Mar 2022 20:25:04 -0700 (PDT) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4KJFwk67vVzfYsR; Wed, 16 Mar 2022 11:23:34 +0800 (CST) Received: from [10.174.177.215] (10.174.177.215) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 16 Mar 2022 11:25:01 +0800 Subject: Re: [PATCH bpf-next] bpf, sockmap: Manual deletion of sockmap elements in user mode is not allowed To: Jakub Sitnicki CC: , , , , , , , , , , , , References: <20220314124432.3050394-1-wangyufen@huawei.com> <87sfrky2bt.fsf@cloudflare.com> <87fsnjxvho.fsf@cloudflare.com> From: wangyufen Message-ID: Date: Wed, 16 Mar 2022 11:25:01 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <87fsnjxvho.fsf@cloudflare.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.215] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org 在 2022/3/15 20:12, Jakub Sitnicki 写道: > On Tue, Mar 15, 2022 at 03:24 PM +08, wangyufen wrote: >> 在 2022/3/14 23:30, Jakub Sitnicki 写道: >>> On Mon, Mar 14, 2022 at 08:44 PM +08, Wang Yufen wrote: >>>> A tcp socket in a sockmap. If user invokes bpf_map_delete_elem to delete >>>> the sockmap element, the tcp socket will switch to use the TCP protocol >>>> stack to send and receive packets. The switching process may cause some >>>> issues, such as if some msgs exist in the ingress queue and are cleared >>>> by sk_psock_drop(), the packets are lost, and the tcp data is abnormal. >>>> >>>> Signed-off-by: Wang Yufen >>>> --- >>> Can you please tell us a bit more about the life-cycle of the socket in >>> your workload? Questions that come to mind: >>> >>> 1) What triggers the removal of the socket from sockmap in your case? >> We use sk_msg to redirect with sock hash, like this: >> >>  skA   redirect    skB >>  Tx <-----------> skB,Rx >> >> And construct a scenario where the packet sending speed is high, the >> packet receiving speed is slow, so the packets are stacked in the ingress >> queue on the receiving side. In this case, if run bpf_map_delete_elem() to >> delete the sockmap entry, will trigger the following procedure: >> >> sock_hash_delete_elem() >>   sock_map_unref() >>     sk_psock_put() >>       sk_psock_drop() >>         sk_psock_stop() >>           __sk_psock_zap_ingress() >>             __sk_psock_purge_ingress_msg() >> >>> 2) Would it still be a problem if removal from sockmap did not cause any >>> packets to get dropped? >> Yes, it still be a problem. If removal from sockmap  did not cause any >> packets to get dropped, packet receiving process switches to use TCP >> protocol stack. The packets in the psock ingress queue cannot be received >> >> by the user. > Thanks for the context. So, if I understand correctly, you want to avoid > breaking the network pipe by updating the sockmap from user-space. > > This sounds awfully similar to BPF_MAP_FREEZE. Have you considered that? > . Sorry, I didn't notice this. I used BPF_MAP_FREEZE to verify, can solve my problem, thanks.