Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7148521ybi; Mon, 8 Jul 2019 15:37:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwGAB5Yx1fRap74mdgPK6zyQWO5Xal49XNd9h0d8QDQxcgEzVx6+4nS5TRUV/YW0TaxbGI9 X-Received: by 2002:a63:9245:: with SMTP id s5mr11698276pgn.123.1562625425385; Mon, 08 Jul 2019 15:37:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562625425; cv=none; d=google.com; s=arc-20160816; b=mz64njegXBRCaAjXvI9IJxaXYywpRLV7St7KxDXdzhfdqHaQCAeIUGQk1CSKcMU7Rz +Q7vLGJVZVlpz2vH/hUdGylVDs7xkR5nkNySliOm3MyziLxsQMBsPtrnxrNxZiIaTGA8 v52onr6Dobvq/pVIPI3WGgNsB2RsDhAmVE9KxGlLQHJk1oz12tvPDqkTPkX0TByXHkaV hn7oYw38bMRC9/qfd8VpuFWM4bwJcArkZIhv12jSuzmpplbMH5gtjlYWopxeAoKu9vaJ /v1ccLPZRn3amYGWMp1M5hpl3K8LZhF9I2b0JADvm0v+uxnhtbQI4l0zRcxqMVLPtYoS CgqA== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=L55i6eoFbTIm3OBE9+sii80XnP0PWbwForqi7TP+HP0=; b=tA2+zr2JK0VILSGYqFUCw1p22AWwBT2Xo4i/E9ANn/hCDtjvlCBf+PrMPijgdiRjG7 S3sPdAcyZPImeLjfrgd5vjzUCQS9THLCJospA+iBcH6mcvjg6pri2OZBkBWhSjB4r0Ig 7DRTIXhY1gvEOE5ym57XOUptOzm0w48IcroLxQfKDdbV9SKGrL+tLWeBH3Nggzifilay bi2A9vhVlWAPGr+PDpM0Dk25+pSJz0jr7XGDd6ajMcAWh4KC2mzhNtyWpn0aDnhiBPIn zHskUrmfFrWhcrWJMaAP/zNNGyBi6CIOZ+UBigRKDfI1bY1yG+yqVfU/WZG3wnRdSrKy K61Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qz4vmM6y; 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 j192si21317692pge.393.2019.07.08.15.36.51; Mon, 08 Jul 2019 15:37:05 -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=qz4vmM6y; 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 S2388510AbfGHPY4 (ORCPT + 99 others); Mon, 8 Jul 2019 11:24:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:52160 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388393AbfGHPYt (ORCPT ); Mon, 8 Jul 2019 11:24:49 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 4CFDB20665; Mon, 8 Jul 2019 15:24:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1562599488; bh=5EPvFDkWTi7S1bCoNPsJ7tsaPgocg3PRyakfKGcKUnA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qz4vmM6y+75dWKW7tvlx5p33tmmNdpyA1X4E/qZmbIy3IEZBoEpekHigOSXc67dHG 2SUCK7DEOmKi/XUIaQ1+pfMrnLItG5kMFchBgJtSh3XuvZEA+OHkYYkcioETXm919X fyJGxyWuZfnqg/txmBZTxFf2uPHTKzIESS/bgvy0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eiichi Tsukata , "Steven Rostedt (VMware)" Subject: [PATCH 4.14 32/56] tracing/snapshot: Resize spare buffer if size changed Date: Mon, 8 Jul 2019 17:13:24 +0200 Message-Id: <20190708150522.894628460@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190708150514.376317156@linuxfoundation.org> References: <20190708150514.376317156@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eiichi Tsukata commit 46cc0b44428d0f0e81f11ea98217fc0edfbeab07 upstream. Current snapshot implementation swaps two ring_buffers even though their sizes are different from each other, that can cause an inconsistency between the contents of buffer_size_kb file and the current buffer size. For example: # cat buffer_size_kb 7 (expanded: 1408) # echo 1 > events/enable # grep bytes per_cpu/cpu0/stats bytes: 1441020 # echo 1 > snapshot // current:1408, spare:1408 # echo 123 > buffer_size_kb // current:123, spare:1408 # echo 1 > snapshot // current:1408, spare:123 # grep bytes per_cpu/cpu0/stats bytes: 1443700 # cat buffer_size_kb 123 // != current:1408 And also, a similar per-cpu case hits the following WARNING: Reproducer: # echo 1 > per_cpu/cpu0/snapshot # echo 123 > buffer_size_kb # echo 1 > per_cpu/cpu0/snapshot WARNING: WARNING: CPU: 0 PID: 1946 at kernel/trace/trace.c:1607 update_max_tr_single.part.0+0x2b8/0x380 Modules linked in: CPU: 0 PID: 1946 Comm: bash Not tainted 5.2.0-rc6 #20 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-2.fc30 04/01/2014 RIP: 0010:update_max_tr_single.part.0+0x2b8/0x380 Code: ff e8 dc da f9 ff 0f 0b e9 88 fe ff ff e8 d0 da f9 ff 44 89 ee bf f5 ff ff ff e8 33 dc f9 ff 41 83 fd f5 74 96 e8 b8 da f9 ff <0f> 0b eb 8d e8 af da f9 ff 0f 0b e9 bf fd ff ff e8 a3 da f9 ff 48 RSP: 0018:ffff888063e4fca0 EFLAGS: 00010093 RAX: ffff888066214380 RBX: ffffffff99850fe0 RCX: ffffffff964298a8 RDX: 0000000000000000 RSI: 00000000fffffff5 RDI: 0000000000000005 RBP: 1ffff1100c7c9f96 R08: ffff888066214380 R09: ffffed100c7c9f9b R10: ffffed100c7c9f9a R11: 0000000000000003 R12: 0000000000000000 R13: 00000000ffffffea R14: ffff888066214380 R15: ffffffff99851060 FS: 00007f9f8173c700(0000) GS:ffff88806d000000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000714dc0 CR3: 0000000066fa6000 CR4: 00000000000006f0 Call Trace: ? trace_array_printk_buf+0x140/0x140 ? __mutex_lock_slowpath+0x10/0x10 tracing_snapshot_write+0x4c8/0x7f0 ? trace_printk_init_buffers+0x60/0x60 ? selinux_file_permission+0x3b/0x540 ? tracer_preempt_off+0x38/0x506 ? trace_printk_init_buffers+0x60/0x60 __vfs_write+0x81/0x100 vfs_write+0x1e1/0x560 ksys_write+0x126/0x250 ? __ia32_sys_read+0xb0/0xb0 ? do_syscall_64+0x1f/0x390 do_syscall_64+0xc1/0x390 entry_SYSCALL_64_after_hwframe+0x49/0xbe This patch adds resize_buffer_duplicate_size() to check if there is a difference between current/spare buffer sizes and resize a spare buffer if necessary. Link: http://lkml.kernel.org/r/20190625012910.13109-1-devel@etsukata.com Cc: stable@vger.kernel.org Fixes: ad909e21bbe69 ("tracing: Add internal tracing_snapshot() functions") Signed-off-by: Eiichi Tsukata Signed-off-by: Steven Rostedt (VMware) Signed-off-by: Greg Kroah-Hartman --- kernel/trace/trace.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c @@ -6394,11 +6394,13 @@ tracing_snapshot_write(struct file *filp break; } #endif - if (!tr->allocated_snapshot) { + if (tr->allocated_snapshot) + ret = resize_buffer_duplicate_size(&tr->max_buffer, + &tr->trace_buffer, iter->cpu_file); + else ret = tracing_alloc_snapshot_instance(tr); - if (ret < 0) - break; - } + if (ret < 0) + break; local_irq_disable(); /* Now, we're going to swap */ if (iter->cpu_file == RING_BUFFER_ALL_CPUS)