Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4615768pxj; Tue, 22 Jun 2021 04:25:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxuZqxcV0/KKFEqVGHBDYsVDTsCLL5kA/4Oykz7Cr53gztGt3xqO209y6kgxHg1s5egCdqQ X-Received: by 2002:a17:906:dbcd:: with SMTP id yc13mr3396045ejb.161.1624361111500; Tue, 22 Jun 2021 04:25:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624361111; cv=none; d=google.com; s=arc-20160816; b=qTUtC3u1z8ZIPPrqCdP8TCzcyd+9kKexRZDMnYx+qKdS/h0ZHlUGpQ719a8/XM1Id8 fr7vV1unULGzIN4DUKGNwXpbkD1Q8LD/l0mY7o/J/DOxSN8MUV1uXZhjCZG3LUGx+Xca hAA6zEzm4YAt5FiNTrNSqbpL7E1JG51KUEYAQ9ZRR4vyKDncVSJ0aGWSIGl6/rjRrtBk vCR2Og1AYGeHXj7g7zBk1BanRG1vHpBR1ZHYy7USzqtV2IjpVjn4f3QWU2yEXTYnkGPB NecjtQJP8TtRC9LykSWW4E04v55Dn/Dn6p7mKBBlNZkj6tAY18rr/lU1awuLxGmj0WZ7 qs6w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=EzKdjYwWYcDoxD6fB6Ye2fiEKa0mV+BCrqAYhAI3wxA=; b=VrOPJ6LIiHf57yV2uGs/vMMBLU8Kp9VEw6USPGxRlrUn1jGP5Qx8mM/83hwx5IvAgo v/hEziWjwoA/MrBXDsAvSpJYyI76afxOcwF5eb3L3gDyfizkDPg5A7asD5SrK6pvFI4v mOVudBci066sH8X/20gF/DgPc3FV8EnBUwp3uXIv2xXIdH/qUwtvmvPhtffOc43RLWW8 cGQEf2iLffQfV5wwVQIBIiFS/qNmhFHr6+bdrcH3bb/pADIXsPCwLWKOsgFztlPuwhjr Z7VUuPuX+hymqsThOhu/oim11LErRPeAc5MjD78iHPE5RtobA2iFFl+Pa3G8BDw3R4dm hdxQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si13207782ejb.113.2021.06.22.04.24.48; Tue, 22 Jun 2021 04:25:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229948AbhFVLYW (ORCPT + 99 others); Tue, 22 Jun 2021 07:24:22 -0400 Received: from mailout1.secunet.com ([62.96.220.44]:60190 "EHLO mailout1.secunet.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229567AbhFVLYS (ORCPT ); Tue, 22 Jun 2021 07:24:18 -0400 Received: from cas-essen-01.secunet.de (unknown [10.53.40.201]) by mailout1.secunet.com (Postfix) with ESMTP id 5323680004E; Tue, 22 Jun 2021 13:22:00 +0200 (CEST) Received: from mbx-essen-01.secunet.de (10.53.40.197) by cas-essen-01.secunet.de (10.53.40.201) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 22 Jun 2021 13:22:00 +0200 Received: from gauss2.secunet.de (10.182.7.193) by mbx-essen-01.secunet.de (10.53.40.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Tue, 22 Jun 2021 13:21:59 +0200 Received: by gauss2.secunet.de (Postfix, from userid 1000) id 681FC318045C; Tue, 22 Jun 2021 13:21:59 +0200 (CEST) Date: Tue, 22 Jun 2021 13:21:59 +0200 From: Steffen Klassert To: Varad Gautam CC: , linux-rt-users , , Herbert Xu , "David S. Miller" , "Jakub Kicinski" , Florian Westphal , "Ahmed S. Darwish" , Frederic Weisbecker , Subject: Re: [PATCH] xfrm: policy: Restructure RCU-read locking in xfrm_sk_policy_lookup Message-ID: <20210622112159.GC40979@gauss3.secunet.de> References: <20210618141101.18168-1-varad.gautam@suse.com> <20210621082949.GX40979@gauss3.secunet.de> <20210621110528.GZ40979@gauss3.secunet.de> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20210621110528.GZ40979@gauss3.secunet.de> X-ClientProxiedBy: cas-essen-01.secunet.de (10.53.40.201) To mbx-essen-01.secunet.de (10.53.40.197) X-EXCLAIMER-MD-CONFIG: 2c86f778-e09b-4440-8b15-867914633a10 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 21, 2021 at 01:05:28PM +0200, Steffen Klassert wrote: > On Mon, Jun 21, 2021 at 11:11:18AM +0200, Varad Gautam wrote: > > > > Right, I misread the call chain - security_xfrm_policy_lookup does not reach > > xfrm_policy_lookup, making this patch unnecessary. The bug I have is: > > > > T1, holding hash_resize_mutex and sleeping inside synchronize_rcu: > > > > __schedule > > schedule > > schedule_timeout > > wait_for_completion > > __wait_rcu_gp > > synchronize_rcu > > xfrm_hash_resize > > > > And T2 producing RCU-stalls since it blocked on the mutex: > > > > __schedule > > schedule > > __rt_mutex_slowlock > > rt_mutex_slowlock_locked > > rt_mutex_slowlock > > xfrm_policy_lookup_bytype.constprop.77 > > Ugh, why does xfrm_policy_lookup_bytype use a mutex? This is called > in the receive path inside a sofirq. > > The bug was introduced by: > > commit 77cc278f7b202e4f16f8596837219d02cb090b96 > Author: Ahmed S. Darwish > Date: Mon Jul 20 17:55:22 2020 +0200 > > xfrm: policy: Use sequence counters with associated lock > > A sequence counter write side critical section must be protected by some > form of locking to serialize writers. If the serialization primitive is > not disabling preemption implicitly, preemption has to be explicitly > disabled before entering the sequence counter write side critical > section. > > A plain seqcount_t does not contain the information of which lock must > be held when entering a write side critical section. > > Use the new seqcount_spinlock_t and seqcount_mutex_t data types instead, > which allow to associate a lock with the sequence counter. This enables > lockdep to verify that the lock used for writer serialization is held > when the write side critical section is entered. > > If lockdep is disabled this lock association is compiled out and has > neither storage size nor runtime overhead. > > Signed-off-by: Ahmed S. Darwish > Signed-off-by: Peter Zijlstra (Intel) > Link: https://lkml.kernel.org/r/20200720155530.1173732-17-a.darwish@linutronix.de > > This uses a seqcount_mutex_t for xfrm_policy_hash_generation, that's > wrong. Varad, can you try to replace the seqcount_mutex_t for xfrm_policy_hash_generation by a seqcount_spinlock_t? I'm not familiar with that seqcount changes, but we should not end up with using a mutex in this codepath.