Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3978251ybg; Mon, 21 Oct 2019 01:39:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqzB5YvvecJwx6UAoigg2PRx7XBZxh/LRGSze488TYajxbPWeTx8WDRAD1CvcncUHu7bp+FR X-Received: by 2002:a50:875e:: with SMTP id 30mr5200664edv.45.1571647195866; Mon, 21 Oct 2019 01:39:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571647195; cv=none; d=google.com; s=arc-20160816; b=V8byl1EBI4ymDSKt1cqcNFWc1vsG9jo0INc2ZNDU/nPjx5hEOE3qif9kgcOo27ULNc ykSLMuwjsMpPPr1VvZqfiiqqUYCFjSg38A7C3S+GkHodn2KT9ECcAla7r1N7K//J2bzX Pi3JbCB7IqotG1aIsV5faEowBftPqU3NvvLCIQtY1UVJWNmFGu2rW0YKMvDC4ovxw7rg LJnCmGfvOp0ajhFhaM5+/ecgOd3prj2QjpigTHVdyUlGhvLKrKilwwdM3gmY5iaYJSEk nC4j+QJKkjxX+4kN22SB042qTZdshVhKrCoepBYMx6Cc3CiR6xiavuxtDzdq+1CN5J/Z FyIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=eT34Rs4WTwuRSwP8YF1Q3p1ZvyDALz6PFFb77d4VYrU=; b=c3n23SISrEDjSYrS94SaUZVCbjhQ8kiuk0HdU5XqHrEQWb/tlsCvv1qBxd4GbGVbII sm709QC+XwCihl8RoIzEfiNloFUz81KhzdyVJXC2tKr13BN4nHwSIMz/b+76CVnckJdw 6Ih3fVDnpQgd2wJOiCXsj6BBprVq0cs5TeBwL7yUKD2bbfutSLanSvebHxtDDrLvpcPx u0InlQGAPti6Pb9MIfyhqpwETTpFn/wNaFjquYQ3MdX/q1Eh0PbTAG5nK6yCVr6fxfjY yEH9wMBuKTZ19r+y3nuywzjvx8t+EQwLQ4/De/5Aq+BSaJ/EmqHHwWqzM7o7UAWtoqtD c+FQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si10057214edb.63.2019.10.21.01.39.33; Mon, 21 Oct 2019 01:39:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727399AbfJUIhe (ORCPT + 99 others); Mon, 21 Oct 2019 04:37:34 -0400 Received: from a.mx.secunet.com ([62.96.220.36]:52558 "EHLO a.mx.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726181AbfJUIhd (ORCPT ); Mon, 21 Oct 2019 04:37:33 -0400 Received: from localhost (localhost [127.0.0.1]) by a.mx.secunet.com (Postfix) with ESMTP id ADFFA204E0; Mon, 21 Oct 2019 10:37:32 +0200 (CEST) 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 zNGTWRgXWIcU; Mon, 21 Oct 2019 10:37:32 +0200 (CEST) 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 44981200A0; Mon, 21 Oct 2019 10:37:32 +0200 (CEST) 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.439.0; Mon, 21 Oct 2019 10:37:28 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id 43CC531800D5; Mon, 21 Oct 2019 10:37:31 +0200 (CEST) Date: Mon, 21 Oct 2019 10:37:31 +0200 From: Steffen Klassert To: Tom Rix CC: , , , Subject: Re: [PATCH] xfrm : lock input tasklet skb queue Message-ID: <20191021083731.GK15862@gauss3.secunet.de> References: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 20, 2019 at 08:46:10AM -0700, Tom Rix wrote: > On PREEMPT_RT_FULL while running netperf, a corruption > of the skb queue causes an oops. > > This appears to be caused by a race condition here > __skb_queue_tail(&trans->queue, skb); > tasklet_schedule(&trans->tasklet); > Where the queue is changed before the tasklet is locked by > tasklet_schedule. > > The fix is to use the skb queue lock. > > Signed-off-by: Tom Rix > --- > net/xfrm/xfrm_input.c | 11 ++++++++++- > 1 file changed, 10 insertions(+), 1 deletion(-) > > diff --git a/net/xfrm/xfrm_input.c b/net/xfrm/xfrm_input.c > index 9b599ed66d97..226dead86828 100644 > --- a/net/xfrm/xfrm_input.c > +++ b/net/xfrm/xfrm_input.c > @@ -758,12 +758,16 @@ static void xfrm_trans_reinject(unsigned long data) > struct xfrm_trans_tasklet *trans = (void *)data; > struct sk_buff_head queue; > struct sk_buff *skb; > + unsigned long flags; > > __skb_queue_head_init(&queue); > + spin_lock_irqsave(&trans->queue.lock, flags); > skb_queue_splice_init(&trans->queue, &queue); > > while ((skb = __skb_dequeue(&queue))) > XFRM_TRANS_SKB_CB(skb)->finish(dev_net(skb->dev), NULL, skb); > + > + spin_unlock_irqrestore(&trans->queue.lock, flags); > } > > int xfrm_trans_queue(struct sk_buff *skb, > @@ -771,15 +775,20 @@ int xfrm_trans_queue(struct sk_buff *skb, > struct sk_buff *)) > { > struct xfrm_trans_tasklet *trans; > + unsigned long flags; > > trans = this_cpu_ptr(&xfrm_trans_tasklet); > + spin_lock_irqsave(&trans->queue.lock, flags); As you can see above 'trans' is per cpu, so a spinlock is not needed here. Also this does not run in hard interrupt context, so irqsave is also not needed. I don't see how this can fix anything. Can you please explain that race a bit more detailed?