Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp31451ybh; Mon, 20 Jul 2020 09:36:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU8UCZzy0gl/9L+1xh6n1TGbuVzdEYe85XMGBTYQ1UGZ0AbtAYRVhVOIIuxFB3+BTqi2pY X-Received: by 2002:aa7:d043:: with SMTP id n3mr22935528edo.102.1595262961696; Mon, 20 Jul 2020 09:36:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595262961; cv=none; d=google.com; s=arc-20160816; b=nKq+BIpLDu84YVNENegKY6G1h3Nko4ZAdR8U4r/BvQLz4KotsLkQpEr+sJ9QBKSgGY x7ive8jVbMKSYghuUDkkH8kNiSeqKjankt1Q3O0mC+U17V1S1uDHZ6qLbTEwjfG9MjVk WIIV3wpjNQKc0qDTzLkory2N3IyL0Hry9G87xO+M5Jy5JLucEePNH0xxfcj3UhbArkLE 5sQWK777/py8e1aYBsppA0OHo2Fs60H+3eqDr5JU+V1XaP2g2Unl7xIcQVPxTl92ZbqL hManT1iKVF5YCQPRkdiEmnwtZtEYU3OAEbbEM3negFg457Yo2Q0OH1Hp5FW3vGauk0MY 0d1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :dkim-signature:from; bh=fDImi88zFV81pjdnOgUX9XebIgS39WaOUsCCEI1b+mc=; b=fMS7SN7lGcHegHMuJvU9ZJ/UDSN4x/b0viMFfnrIRFXAZgdATUCupOSE09melMUekd Eo9+2FV/LfRA687T9ovFwpLcQgUWFMBeM3c/pIKU8Nf19DO9sMbMA7xK7HtPx0oipdUD O6uUxMtXgbWuPUTrn7JCQiB5eN3x3qNoIVqF2p/Ne29EItkBsG/hXLMRPkm1HxcF+EOD 1p+XTCsuVHZZYAfry23J9IyiaKbvPbEmoy8DvlLjJh4StDtvxnoyQ0s0vzZbNp2F683X jqvhAcMEpOgCF7Sjk6oTFtN2vsbA2Cmz0zQNEeJFhgA7PT0W5sYKkmCjq+8DqC9pD4PR x8kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iD4xnpX0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a1si10343479edv.245.2020.07.20.09.35.34; Mon, 20 Jul 2020 09:36:01 -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; dkim=pass header.i=@linutronix.de header.s=2020 header.b=iD4xnpX0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732394AbgGTQcN (ORCPT + 99 others); Mon, 20 Jul 2020 12:32:13 -0400 Received: from Galois.linutronix.de ([193.142.43.55]:58898 "EHLO galois.linutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731831AbgGTP4v (ORCPT ); Mon, 20 Jul 2020 11:56:51 -0400 From: "Ahmed S. Darwish" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1595260608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fDImi88zFV81pjdnOgUX9XebIgS39WaOUsCCEI1b+mc=; b=iD4xnpX0iRZgogyjOiHVrZQNGX7nsG9CgZhEFPYHTEdTFe8WWzp+BUtL1SZzNO5LEdU91C MfN7kWQWUa/ZSUut/7hgdhQz0nxS7tHis1FOPupATFdK+Is3TQHURz7RqUXFGfeayWmMZa E7gpnw3gLweWsoXyedn5AU1ITR2cR1wG9zkNnHCk4rejk/9hI+z0Y9q/E0mZ4zHe2/tS5V OGCClXH2nwmhnSIgORzreuKhFhMzQBeZiXuhPgRAOdr8uT7Toc/rnBBpKCi0eh5GtJgSiI nnWVpwdm7ETkC5djyIsNSJZdVK4K6FVvm9ANOth6AVAs1YAZpursJ+XOOFXglQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1595260608; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fDImi88zFV81pjdnOgUX9XebIgS39WaOUsCCEI1b+mc=; b=g6j7cwiXCKepe4U21OZ5BfpK36kd8eTsYX4jbS3n9Cu1A5VTcDUF0yLW52NzEAkZ3nlWem 2GCVU32cKO8fF8Bg== To: Peter Zijlstra , Ingo Molnar , Will Deacon Cc: Thomas Gleixner , "Paul E. McKenney" , "Sebastian A. Siewior" , Steven Rostedt , LKML , "Ahmed S. Darwish" , Steffen Klassert , Herbert Xu , "David S. Miller" , Jakub Kicinski , netdev@vger.kernel.org Subject: [PATCH v4 16/24] xfrm: policy: Use sequence counters with associated lock Date: Mon, 20 Jul 2020 17:55:22 +0200 Message-Id: <20200720155530.1173732-17-a.darwish@linutronix.de> In-Reply-To: <20200720155530.1173732-1-a.darwish@linutronix.de> References: <20200519214547.352050-1-a.darwish@linutronix.de> <20200720155530.1173732-1-a.darwish@linutronix.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- net/xfrm/xfrm_policy.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c index 564aa6492e7c..732a940468b0 100644 --- a/net/xfrm/xfrm_policy.c +++ b/net/xfrm/xfrm_policy.c @@ -122,7 +122,7 @@ struct xfrm_pol_inexact_bin { /* list containing '*:*' policies */ struct hlist_head hhead; - seqcount_t count; + seqcount_spinlock_t count; /* tree sorted by daddr/prefix */ struct rb_root root_d; @@ -155,7 +155,7 @@ static struct xfrm_policy_afinfo const __rcu *xfrm_policy_afinfo[AF_INET6 + 1] __read_mostly; static struct kmem_cache *xfrm_dst_cache __ro_after_init; -static __read_mostly seqcount_t xfrm_policy_hash_generation; +static __read_mostly seqcount_mutex_t xfrm_policy_hash_generation; static struct rhashtable xfrm_policy_inexact_table; static const struct rhashtable_params xfrm_pol_inexact_params; @@ -719,7 +719,7 @@ xfrm_policy_inexact_alloc_bin(const struct xfrm_policy *pol, u8 dir) INIT_HLIST_HEAD(&bin->hhead); bin->root_d = RB_ROOT; bin->root_s = RB_ROOT; - seqcount_init(&bin->count); + seqcount_spinlock_init(&bin->count, &net->xfrm.xfrm_policy_lock); prev = rhashtable_lookup_get_insert_key(&xfrm_policy_inexact_table, &bin->k, &bin->head, @@ -1906,7 +1906,7 @@ static int xfrm_policy_match(const struct xfrm_policy *pol, static struct xfrm_pol_inexact_node * xfrm_policy_lookup_inexact_addr(const struct rb_root *r, - seqcount_t *count, + seqcount_spinlock_t *count, const xfrm_address_t *addr, u16 family) { const struct rb_node *parent; @@ -4153,7 +4153,7 @@ void __init xfrm_init(void) { register_pernet_subsys(&xfrm_net_ops); xfrm_dev_init(); - seqcount_init(&xfrm_policy_hash_generation); + seqcount_mutex_init(&xfrm_policy_hash_generation, &hash_resize_mutex); xfrm_input_init(); #ifdef CONFIG_INET_ESPINTCP -- 2.20.1