Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.5 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 176E5C169C4 for ; Wed, 6 Feb 2019 05:14:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3054218A1 for ; Wed, 6 Feb 2019 05:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728175AbfBFFOw (ORCPT ); Wed, 6 Feb 2019 00:14:52 -0500 Received: from a.mx.secunet.com ([62.96.220.36]:59270 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726051AbfBFFOw (ORCPT ); Wed, 6 Feb 2019 00:14:52 -0500 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id D329F20189; Wed, 6 Feb 2019 06:14:50 +0100 (CET) X-Virus-Scanned: by secunet Received: from a.mx.secunet.com ([127.0.0.1]) by localhost (a.mx.secunet.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C-fojp26PghB; Wed, 6 Feb 2019 06:14:50 +0100 (CET) Received: from mail-essen-01.secunet.de (mail-essen-01.secunet.de [10.53.40.204]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by a.mx.secunet.com (Postfix) with ESMTPS id 63C4420068; Wed, 6 Feb 2019 06:14:50 +0100 (CET) Received: from gauss2.secunet.de (10.182.7.193) by mail-essen-01.secunet.de (10.53.40.204) with Microsoft SMTP Server id 14.3.435.0; Wed, 6 Feb 2019 06:14:49 +0100 Received: by gauss2.secunet.de (Postfix, from userid 1000) id DD51931826E7; Wed, 6 Feb 2019 06:14:49 +0100 (CET) Date: Wed, 6 Feb 2019 06:14:49 +0100 From: Steffen Klassert To: Cong Wang CC: , Subject: Re: [Patch net v2] xfrm: destroy xfrm_state synchronously on net exit path Message-ID: <20190206051449.GD3087@gauss3.secunet.de> References: <20190131210549.3114-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20190131210549.3114-1-xiyou.wangcong@gmail.com> User-Agent: Mutt/1.9.4 (2018-02-28) X-G-Data-MailSecurity-for-Exchange-State: 0 X-G-Data-MailSecurity-for-Exchange-Error: 0 X-G-Data-MailSecurity-for-Exchange-Sender: 23 X-G-Data-MailSecurity-for-Exchange-Server: d65e63f7-5c15-413f-8f63-c0d707471c93 X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 X-G-Data-MailSecurity-for-Exchange-Guid: E4E344BE-0050-4208-9716-E4FC5BCEA515 X-G-Data-MailSecurity-for-Exchange-ProcessedOnRouted: True Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Thu, Jan 31, 2019 at 01:05:49PM -0800, Cong Wang wrote: > xfrm_state_put() moves struct xfrm_state to the GC list > and schedules the GC work to clean it up. On net exit call > path, xfrm_state_flush() is called to clean up and > xfrm_flush_gc() is called to wait for the GC work to complete > before exit. > > However, this doesn't work because one of the ->destructor(), > ipcomp_destroy(), schedules the same GC work again inside > the GC work. It is hard to wait for such a nested async > callback. This is also why syzbot still reports the following > warning: > > WARNING: CPU: 1 PID: 33 at net/ipv6/xfrm6_tunnel.c:351 xfrm6_tunnel_net_exit+0x2cb/0x500 net/ipv6/xfrm6_tunnel.c:351 > ... > ops_exit_list.isra.0+0xb0/0x160 net/core/net_namespace.c:153 > cleanup_net+0x51d/0xb10 net/core/net_namespace.c:551 > process_one_work+0xd0c/0x1ce0 kernel/workqueue.c:2153 > worker_thread+0x143/0x14a0 kernel/workqueue.c:2296 > kthread+0x357/0x430 kernel/kthread.c:246 > ret_from_fork+0x3a/0x50 arch/x86/entry/entry_64.S:352 > > In fact, it is perfectly fine to bypass GC and destroy xfrm_state > synchronously on net exit call path, because it is in process context > and doesn't need a work struct to do any blocking work. > > This patch introduces xfrm_state_put_sync() which simply bypasses > GC, and lets its callers to decide whether to use this synchronous > version. On net exit path, xfrm_state_fini() and > xfrm6_tunnel_net_exit() use it. And, as ipcomp_destroy() itself is > blocking, it can use xfrm_state_put_sync() directly too. > > Also rename xfrm_state_gc_destroy() to ___xfrm_state_destroy() to > reflect this change. > > Fixes: b48c05ab5d32 ("xfrm: Fix warning in xfrm6_tunnel_net_exit.") > Reported-and-tested-by: syzbot+e9aebef558e3ed673934@syzkaller.appspotmail.com > Cc: Steffen Klassert > Signed-off-by: Cong Wang Applied, thanks a lot!