Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1512242imm; Wed, 10 Oct 2018 16:16:17 -0700 (PDT) X-Google-Smtp-Source: ACcGV63yvMXV82WGywtYyedAqHfh44z4WKrxIlta8zBmQEj5cr0AIOYIpUJq/3G0Eh2FD1hJewGl X-Received: by 2002:a62:c957:: with SMTP id k84-v6mr37671320pfg.205.1539213377239; Wed, 10 Oct 2018 16:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539213377; cv=none; d=google.com; s=arc-20160816; b=fy/n8jz6e+WICwR/7uo+9DgavAM4fS5+WT6zObhTdYq49U2TKIdxGaP/zuyAQ19ZMR M6C2VI4miwfCG4B9GCvsejB5pJJn5sATZfSrHQWnCNcp17QwuM0B865UJ4KN6YT29rv0 ibBrAcQoINlh9y+LEOiKR2n4nikM8H/NOH9iRFyVY0cqsgyooGbfEY+FokB23zZa3kEq 5+fA0jGDEEZm30zA6wyp3eawDgvKkio8JY5llrDaam5a3+s2cOV/S198KdYYI4Fut0O2 W5xhtR1CTVYkodTF1GfKbyspZbTxoSEBrl0HvmbIbjuxqllw/OrCKGrj0La4EOD6zLIZ 4XsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=PuiTagao93BCe29pvXPiASUA6mEjMbk06VQak9Ftjac=; b=kWhaZIPaTsDiVmea6bPW2h+3IhvS5dubPaXtIiGiktEkhe0pjRX0iK5pvdTBiyiXQd 9V+of5OwNgVASszZiuSBzo+AS6icR19WjPIpVu0ntRKGSfA6fyJJYjQrzxqSD3nkXmsG 07A2mA2xkdQktSx2l7ewvZlqSz8/L0pIDKrYjx8XxLfyelsrsHpbqYcr3MbdUlwpitYI 4BV3/9+n56yAiRsnW7T7SegtB0jnKBfD8dL8IpW7b3MDgwboobvzb5Jcivrt7AkURQCK 0wuGqFbKZB+OnnXivcWyc4wcNjEp5Bxo0r2XQexznaAtOQEAvFL+S68nGwvzV3udmzmS fuZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="r/ZWwkRN"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j3-v6si26701435pld.380.2018.10.10.16.16.02; Wed, 10 Oct 2018 16:16:17 -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; dkim=pass header.i=@kernel.org header.s=default header.b="r/ZWwkRN"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727353AbeJKGhe (ORCPT + 99 others); Thu, 11 Oct 2018 02:37:34 -0400 Received: from mail.kernel.org ([198.145.29.99]:35732 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727291AbeJKGhd (ORCPT ); Thu, 11 Oct 2018 02:37:33 -0400 Received: from lerouge.suse.de (LFbn-NCY-1-241-207.w83-194.abo.wanadoo.fr [83.194.85.207]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2E26920870; Wed, 10 Oct 2018 23:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539213191; bh=16HZM3xmj3k75vePkaiRGPwlykP1aFYZNw+wOVgg0j8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r/ZWwkRNsuuEROu2t7vy4nWvi4B2R/loDYM6kefSCayLu1fKVwWn44Jhs0MTJfdZN CGERYGzN36JzdaPIAIFaHdP/NdO4TLKvgrdLekzIQ5CU39/qhpF624J93AxKZ7qIjk zc/xZ9xeQ3AuK1HqjtC1HHU89QiKGy7pCcum7JyM= From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Sebastian Andrzej Siewior , Peter Zijlstra , "David S . Miller" , Linus Torvalds , Thomas Gleixner , "Paul E . McKenney" , Ingo Molnar , Frederic Weisbecker , Mauro Carvalho Chehab Subject: [RFC PATCH 13/30] net: Prepare tcp_get_md5sig_pool() for handling softirq mask Date: Thu, 11 Oct 2018 01:12:00 +0200 Message-Id: <1539213137-13953-14-git-send-email-frederic@kernel.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1539213137-13953-1-git-send-email-frederic@kernel.org> References: <1539213137-13953-1-git-send-email-frederic@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This pair of function is implemented on top of local_bh_disable() that is going to handle a softirq mask in order to apply finegrained vector disablement. The lock function is going to return the previous vectors enabled mask prior to the last call to local_bh_disable(), following a similar model to that of local_irq_save/restore. Subsequent calls to local_bh_disable() and friends can then stack up: bh = local_bh_disable(vec_mask); tcp_get_md5sig_pool(&bh2) { *bh2 = local_bh_disable(...) } ... tcp_put_md5sig_pool(bh2) { local_bh_enable(bh2); } local_bh_enable(bh); To prepare for that, make tcp_get_md5sig_pool() able to return a saved vector enabled mask and pass it back to rcu_read_unlock_bh(). We'll plug it to local_bh_disable() in a subsequent patch. Signed-off-by: Frederic Weisbecker Cc: Ingo Molnar Cc: Sebastian Andrzej Siewior Cc: Thomas Gleixner Cc: Peter Zijlstra Cc: Linus Torvalds Cc: David S. Miller Cc: Mauro Carvalho Chehab Cc: Paul E. McKenney --- include/net/tcp.h | 4 ++-- net/ipv4/tcp.c | 5 ++++- net/ipv4/tcp_ipv4.c | 14 ++++++++------ net/ipv6/tcp_ipv6.c | 14 ++++++++------ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/include/net/tcp.h b/include/net/tcp.h index 770917d..7fe357a 100644 --- a/include/net/tcp.h +++ b/include/net/tcp.h @@ -1553,8 +1553,8 @@ static inline struct tcp_md5sig_key *tcp_md5_do_lookup(const struct sock *sk, bool tcp_alloc_md5sig_pool(void); -struct tcp_md5sig_pool *tcp_get_md5sig_pool(void); -static inline void tcp_put_md5sig_pool(void) +struct tcp_md5sig_pool *tcp_get_md5sig_pool(unsigned int *bh); +static inline void tcp_put_md5sig_pool(unsigned int bh) { local_bh_enable(); } diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 10c6246..dfd9bae 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -3665,16 +3665,19 @@ EXPORT_SYMBOL(tcp_alloc_md5sig_pool); * and BH disabled, to make sure another thread or softirq handling * wont try to get same context. */ -struct tcp_md5sig_pool *tcp_get_md5sig_pool(void) +struct tcp_md5sig_pool *tcp_get_md5sig_pool(unsigned int *bh) { local_bh_disable(); + *bh = 0; if (tcp_md5sig_pool_populated) { /* coupled with smp_wmb() in __tcp_alloc_md5sig_pool() */ smp_rmb(); return this_cpu_ptr(&tcp_md5sig_pool); } + local_bh_enable(); + return NULL; } EXPORT_SYMBOL(tcp_get_md5sig_pool); diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 44c09ed..0378e77 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1194,8 +1194,9 @@ static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, { struct tcp_md5sig_pool *hp; struct ahash_request *req; + unsigned int bh; - hp = tcp_get_md5sig_pool(); + hp = tcp_get_md5sig_pool(&bh); if (!hp) goto clear_hash_noput; req = hp->md5_req; @@ -1210,11 +1211,11 @@ static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, if (crypto_ahash_final(req)) goto clear_hash; - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); return 0; clear_hash: - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); clear_hash_noput: memset(md5_hash, 0, 16); return 1; @@ -1228,6 +1229,7 @@ int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, struct ahash_request *req; const struct tcphdr *th = tcp_hdr(skb); __be32 saddr, daddr; + unsigned int bh; if (sk) { /* valid for establish/request sockets */ saddr = sk->sk_rcv_saddr; @@ -1238,7 +1240,7 @@ int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, daddr = iph->daddr; } - hp = tcp_get_md5sig_pool(); + hp = tcp_get_md5sig_pool(&bh); if (!hp) goto clear_hash_noput; req = hp->md5_req; @@ -1256,11 +1258,11 @@ int tcp_v4_md5_hash_skb(char *md5_hash, const struct tcp_md5sig_key *key, if (crypto_ahash_final(req)) goto clear_hash; - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); return 0; clear_hash: - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); clear_hash_noput: memset(md5_hash, 0, 16); return 1; diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 03e6b7a..360efc3 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -610,8 +610,9 @@ static int tcp_v6_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, { struct tcp_md5sig_pool *hp; struct ahash_request *req; + unsigned int bh; - hp = tcp_get_md5sig_pool(); + hp = tcp_get_md5sig_pool(&bh); if (!hp) goto clear_hash_noput; req = hp->md5_req; @@ -626,11 +627,11 @@ static int tcp_v6_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key, if (crypto_ahash_final(req)) goto clear_hash; - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); return 0; clear_hash: - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); clear_hash_noput: memset(md5_hash, 0, 16); return 1; @@ -645,6 +646,7 @@ static int tcp_v6_md5_hash_skb(char *md5_hash, struct tcp_md5sig_pool *hp; struct ahash_request *req; const struct tcphdr *th = tcp_hdr(skb); + unsigned int bh; if (sk) { /* valid for establish/request sockets */ saddr = &sk->sk_v6_rcv_saddr; @@ -655,7 +657,7 @@ static int tcp_v6_md5_hash_skb(char *md5_hash, daddr = &ip6h->daddr; } - hp = tcp_get_md5sig_pool(); + hp = tcp_get_md5sig_pool(&bh); if (!hp) goto clear_hash_noput; req = hp->md5_req; @@ -673,11 +675,11 @@ static int tcp_v6_md5_hash_skb(char *md5_hash, if (crypto_ahash_final(req)) goto clear_hash; - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); return 0; clear_hash: - tcp_put_md5sig_pool(); + tcp_put_md5sig_pool(bh); clear_hash_noput: memset(md5_hash, 0, 16); return 1; -- 2.7.4