Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2646181ybl; Mon, 19 Aug 2019 05:30:56 -0700 (PDT) X-Google-Smtp-Source: APXvYqzE1WCOtiXA6lJGCUf2xi9aj70+GcnOdlWaws/NCO0Ag2fudTGl8rUFm89wlygV1BuSPPRO X-Received: by 2002:a17:902:6b81:: with SMTP id p1mr22090163plk.91.1566217856296; Mon, 19 Aug 2019 05:30:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566217856; cv=none; d=google.com; s=arc-20160816; b=gXBEtGDda4MY9VVfkZV9XhgA+IFlIMjzc1vfY+wQGj/ejyqSRwyfKJ9G2Yb9ZFtdUv VBzT7i2MfcQSgrHk1W0VK9gv/kw5SZP5qaM4HWO+9JVVosCK5Yps78epaHaB20YrT0bM cbTiPPdNxgdp8uzvu8H7nybuIA9hglXcx/K7MaIobJbhHbalHSQnMbnkbolV+fDepP5R aHkt8XHk6CPnrrYe5Bfg0V/fQQbZkejlKkLxXQqcGzPRl9ObyNO5avhEwv8k8bLdIoyn SWmY2tI7XLK8n5I0JxQ/3FLDheMUUr6n2RjZXCQQ30wNhKsykks5za/vz3TWerZb7ioZ 7gRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=tSDNac3IpC0XQfaKU1b+CVQPA8G8Z+zM6tWLA7ESmuw=; b=vq8sWfGyKJMtMW/wrS8C5eDp+eCw8QQZfZ9+3kqnd3SUa3og/RQbHB4FlJJM0WrYdA 1gJH36rTmMGy99/1X+bcw69SwkhUjOdQRv1JkwiV8vycTgDgrjkL7VVHIm5srLUMza3Z rLw8yjnwYjhPsFy0UiwKfyPdC6eYz3lzilRE6nVmpX9jXMhDMw+nDNYfpxTRPuzaoVaH +6ptDKYy0uXW9B00pwgYZa3wufLuETBLBwg971Lh+jxRVSbPUYqDpPs/L3JK0sQekV7Z zgMIuxfVTlj3OgkdZLTZNycBdat1YhKMEcsxv033SvJ94Ne4xDGcdBP/fBjeYG2si5iZ mZDA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v11si9672595pgr.237.2019.08.19.05.30.41; Mon, 19 Aug 2019 05:30:56 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727546AbfHSM22 (ORCPT + 99 others); Mon, 19 Aug 2019 08:28:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37053 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727039AbfHSM21 (ORCPT ); Mon, 19 Aug 2019 08:28:27 -0400 Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 00F3EC0740CD for ; Mon, 19 Aug 2019 12:28:27 +0000 (UTC) Received: by mail-wr1-f69.google.com with SMTP id m7so4836253wrw.22 for ; Mon, 19 Aug 2019 05:28:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tSDNac3IpC0XQfaKU1b+CVQPA8G8Z+zM6tWLA7ESmuw=; b=S+MMqXpIKo05uxUzZtIOrsE3OJp52VUBh3ybKOorkrK+aaijzl/eIajLCu/cAXUA/X Y3WsxmU33DbMUXVjlqn/uifC9MVgvCyOo8nXOWDzFFRUvJ40CCX/j0xuGniohjsp0lOg vr3QKmMdONoZhK1gTJPkadASCkFBxlxBFIwbauEyZmRIdgjuhSDKn+QOrUsyc3QZLfkT 6KDee8nh52N/pIAyY0TpO5ULFnFNeEC2Uc9lKuqB8ysPSYe4syXiazKxujG9SBRbUHbx ayWPuz37XYf96yt2w+whm7twDaAJTZUF7CzYj6TJNRe2uBTlv5jQXaNoQexy+vUtcK/r CqzA== X-Gm-Message-State: APjAAAVxunC4O8YHq0jFDEpyqN/lEejkxGNCvDb3yO5oUWvfiCJ4mVCN 3RF+aloEGT7Fqul0KAlJ1ttdCoY+TN1slcRSoYIdYgfSMZvxl4SD9RKAHZ3F4dXYJG7dQzQ5HQl zEyJ9y/70klk/HwXGwLJeuJmH X-Received: by 2002:adf:e50b:: with SMTP id j11mr27033326wrm.65.1566217703716; Mon, 19 Aug 2019 05:28:23 -0700 (PDT) X-Received: by 2002:adf:e50b:: with SMTP id j11mr27033285wrm.65.1566217703342; Mon, 19 Aug 2019 05:28:23 -0700 (PDT) Received: from localhost.localdomain.com ([151.29.237.107]) by smtp.gmail.com with ESMTPSA id a6sm11074431wmj.15.2019.08.19.05.28.21 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 19 Aug 2019 05:28:22 -0700 (PDT) From: Juri Lelli To: tglx@linutronix.de, bigeasy@linutronix.de, rostedt@goodmis.org Cc: linux-rt-users@vger.kernel.org, linux-kernel@vger.kernel.org, williams@redhat.com, Juri Lelli Subject: [RT PATCH v2] net/xfrm/xfrm_ipcomp: Protect scratch buffer with local_lock Date: Mon, 19 Aug 2019 14:27:31 +0200 Message-Id: <20190819122731.6600-1-juri.lelli@redhat.com> X-Mailer: git-send-email 2.17.2 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The following BUG has been reported while running ipsec tests. BUG: scheduling while atomic: irq/78-eno3-rx-/12023/0x00000002 Modules linked in: ipcomp xfrm_ipcomp ... Preemption disabled at: [] ipcomp_input+0xd0/0x9a0 [xfrm_ipcomp] CPU: 1 PID: 12023 Comm: irq/78-eno3-rx- Kdump: loaded Not tainted [...] #1 Hardware name: [...] Call Trace: dump_stack+0x5c/0x80 ? ipcomp_input+0xd0/0x9a0 [xfrm_ipcomp] __schedule_bug.cold.81+0x44/0x51 __schedule+0x5bf/0x6a0 schedule+0x39/0xd0 rt_spin_lock_slowlock_locked+0x10e/0x2b0 rt_spin_lock_slowlock+0x50/0x80 get_page_from_freelist+0x609/0x1560 ? zlib_updatewindow+0x5a/0xd0 __alloc_pages_nodemask+0xd9/0x280 ipcomp_input+0x299/0x9a0 [xfrm_ipcomp] xfrm_input+0x5e3/0x960 xfrm4_ipcomp_rcv+0x34/0x50 ip_local_deliver_finish+0x22d/0x250 ip_local_deliver+0x6d/0x110 ? ip_rcv_finish+0xac/0x480 ip_rcv+0x28e/0x3f9 ? packet_rcv+0x43/0x4c0 __netif_receive_skb_core+0xb7c/0xd10 ? inet_gro_receive+0x8e/0x2f0 netif_receive_skb_internal+0x4a/0x160 napi_gro_receive+0xee/0x110 tg3_rx+0x2a8/0x810 [tg3] tg3_poll_work+0x3b3/0x830 [tg3] tg3_poll_msix+0x3b/0x170 [tg3] net_rx_action+0x1ff/0x470 ? __switch_to_asm+0x41/0x70 do_current_softirqs+0x223/0x3e0 ? irq_thread_check_affinity+0x20/0x20 __local_bh_enable+0x51/0x60 irq_forced_thread_fn+0x5e/0x80 ? irq_finalize_oneshot.part.45+0xf0/0xf0 irq_thread+0x13d/0x1a0 ? wake_threads_waitq+0x30/0x30 kthread+0x112/0x130 ? kthread_create_worker_on_cpu+0x70/0x70 ret_from_fork+0x35/0x40 The problem resides in the fact that get_cpu(), called from ipcomp_input() disables preemption, and that triggers the scheduling while atomic BUG further down the callpath chain of get_page_from_freelist(), i.e., ipcomp_input ipcomp_decompress <-- get_cpu() alloc_page(GFP_ATOMIC) alloc_pages(GFP_ATOMIC, 0) alloc_pages_current __alloc_pages_nodemask get_page_from_freelist (try_this_zone:) rmqueue rmqueue_pcplist __rmqueue_pcplist rmqueue_bulk <-- spin_lock(&zone->lock) - BUG Fix this by replacing get_cpu() with a local lock to protect ipcomp_scratches buffers used by ipcomp_(de)compress(). Suggested-by: Sebastian Andrzej Siewior Signed-off-by: Juri Lelli -- This v2 applies to v4.19.59-rt24. v1 -> v2: Use a local lock instead of {get,put}_cpu_light(), as the latter doesn't protect against multiple CPUs invoking (de)compress function at the same time, thus concurently working on the same scratch buffer. --- net/xfrm/xfrm_ipcomp.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/net/xfrm/xfrm_ipcomp.c b/net/xfrm/xfrm_ipcomp.c index a00ec715aa46..3b4a38febf0a 100644 --- a/net/xfrm/xfrm_ipcomp.c +++ b/net/xfrm/xfrm_ipcomp.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -35,6 +36,7 @@ struct ipcomp_tfms { }; static DEFINE_MUTEX(ipcomp_resource_mutex); +static DEFINE_LOCAL_IRQ_LOCK(ipcomp_scratches_lock); static void * __percpu *ipcomp_scratches; static int ipcomp_scratch_users; static LIST_HEAD(ipcomp_tfms_list); @@ -45,12 +47,14 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb) const int plen = skb->len; int dlen = IPCOMP_SCRATCH_SIZE; const u8 *start = skb->data; - const int cpu = get_cpu(); - u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu); - struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu); - int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen); - int len; + u8 *scratch; + struct crypto_comp *tfm; + int err, len; + local_lock(ipcomp_scratches_lock); + scratch = *this_cpu_ptr(ipcomp_scratches); + tfm = *this_cpu_ptr(ipcd->tfms); + err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen); if (err) goto out; @@ -103,7 +107,7 @@ static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb) err = 0; out: - put_cpu(); + local_unlock(ipcomp_scratches_lock); return err; } @@ -146,6 +150,7 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb) int err; local_bh_disable(); + local_lock(ipcomp_scratches_lock); scratch = *this_cpu_ptr(ipcomp_scratches); tfm = *this_cpu_ptr(ipcd->tfms); err = crypto_comp_compress(tfm, start, plen, scratch, &dlen); @@ -158,12 +163,14 @@ static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb) } memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen); + local_unlock(ipcomp_scratches_lock); local_bh_enable(); pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr)); return 0; out: + local_unlock(ipcomp_scratches_lock); local_bh_enable(); return err; } -- 2.17.2