From patchwork Thu Jan 10 14:27:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 155179 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1956463jaa; Thu, 10 Jan 2019 06:27:54 -0800 (PST) X-Google-Smtp-Source: ALg8bN6RH4q6Dq3dCsWgAG+GcHuEu1NI/v9vG7sgy98DzdugVQRVo4nvTUqT8UibSqKonUY/t/Km X-Received: by 2002:a63:4f20:: with SMTP id d32mr9550125pgb.47.1547130474721; Thu, 10 Jan 2019 06:27:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547130474; cv=none; d=google.com; s=arc-20160816; b=rf9s9Zhx5J4dcT6zyXf3wMcfXMmGjR664wWL/x5dJrkXr6P+2qhHYnx+rt4huk+wrq DxSR/6W8YEgFl1fj8cKC0XM3QQme7fwltU7c3fKKnsWlmO6OcEZ1CurWQn0VpUZPqtXw +4yniIqIKxy1Z2h5582aIuXeIbWIrefQ5XxIlgvLOj32qO8e8g29LZZgNSLQ2vhbXn87 eqnkQbqLSDUoehUJyBmhKNE+SqRrCyFBObxG3iu4jn5OBkaXJFLtnG9au2nmv4MJS0IM vorIKE+J+epWNfBTEFOJgPifXQAcmdSxJ/kgeIWoYXslp9QHBzdwPFAPbH1icsCAW3YV T7qw== 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=9tKa/ACxx2rElKyBIRr+s0rpYvrKMTimwu5h09h3sD0=; b=qafbHVa2NM2K446ZknNqZeMfdtBy5IrQqFS7+E5dNWKOfoBCnD8P+AWr4meRO0jN0q l1L+2jBCGgmJI05WzkF7lJ/+Oys2zSApdwAopfu7h8jB8ld/Gqe+fkkO2fvbWmwsbrz3 0F/vl/r9bRWkVHQPxZdVmpJy0Mf4804UtJ00sA9nXV4vGzC2WtGN+JHLA+hIbgCkavFm Oz6j0hHEv/eKiVuxoLnFjVGssCRBptvQCU6BCvOWVjhmTPBysOUPqji572gkcL/ZGgC7 d6LfXeSdnI3alQpGmnAweWO12BScvGDzoEtOHKGdr6iVVt+MrudGiRt1GwLs+nlhs7oS uHdg== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l22si71846539pgo.411.2019.01.10.06.27.54; Thu, 10 Jan 2019 06:27:54 -0800 (PST) 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729076AbfAJO1x (ORCPT + 31 others); Thu, 10 Jan 2019 09:27:53 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:36986 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728833AbfAJO1x (ORCPT ); Thu, 10 Jan 2019 09:27:53 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 907F01596; Thu, 10 Jan 2019 06:27:52 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 15D003F5AF; Thu, 10 Jan 2019 06:27:50 -0800 (PST) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: julien.thierry@arm.com, Mark Rutland , Alexander Shishkin , Ingo Molnar , Jiri Olsa , Namhyung Kim , Peter Zijlstra Subject: [PATCH] perf/core: don't WARN for impossible rb sizes Date: Thu, 10 Jan 2019 14:27:45 +0000 Message-Id: <20190110142745.25495-1-mark.rutland@arm.com> X-Mailer: git-send-email 2.11.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The perf tool uses /proc/sys/kernel/perf_event_mlock_kb to determine how large its ringbuffer mmap should be. This can be configured to arbitrary values, which can be larger than the maximum possible allocation from kmalloc. When this is configured to a suitably large value (e.g. thanks to the perf fuzzer), attempting to use perf record triggers a WARN_ON_ONCE() in __alloc_pages_nodemask(): [ 337.316688] WARNING: CPU: 2 PID: 5666 at mm/page_alloc.c:4511 __alloc_pages_nodemask+0x3f8/0xbc8 [ 337.316694] Modules linked in: [ 337.316704] CPU: 2 PID: 5666 Comm: perf Not tainted 5.0.0-rc1 #2669 [ 337.316708] Hardware name: ARM Juno development board (r0) (DT) [ 337.316714] pstate: 20000005 (nzCv daif -PAN -UAO) [ 337.316720] pc : __alloc_pages_nodemask+0x3f8/0xbc8 [ 337.316728] lr : alloc_pages_current+0x80/0xe8 [ 337.316732] sp : ffff000016eeb9e0 [ 337.316736] x29: ffff000016eeb9e0 x28: 0000000000080001 [ 337.316744] x27: 0000000000000000 x26: ffff0000111e21f0 [ 337.316751] x25: 0000000000000001 x24: 0000000000000000 [ 337.316757] x23: 0000000000080001 x22: 0000000000000000 [ 337.316762] x21: 0000000000000000 x20: 000000000000000b [ 337.316768] x19: 000000000060c0c0 x18: 0000000000000000 [ 337.316773] x17: 0000000000000000 x16: 0000000000000000 [ 337.316779] x15: 0000000000000000 x14: 0000000000000000 [ 337.316784] x13: 0000000000000000 x12: 0000000000000000 [ 337.316789] x11: 0000000000100000 x10: 0000000000000000 [ 337.316795] x9 : 0000000010044400 x8 : 0000000080001000 [ 337.316800] x7 : 0000000000000000 x6 : ffff800975584700 [ 337.316806] x5 : 0000000000000000 x4 : ffff0000111cd6c8 [ 337.316811] x3 : 0000000000000000 x2 : 0000000000000000 [ 337.316816] x1 : 000000000000000b x0 : 000000000060c0c0 [ 337.316822] Call trace: [ 337.316828] __alloc_pages_nodemask+0x3f8/0xbc8 [ 337.316834] alloc_pages_current+0x80/0xe8 [ 337.316841] kmalloc_order+0x14/0x30 [ 337.316848] __kmalloc+0x1dc/0x240 [ 337.316854] rb_alloc+0x3c/0x170 [ 337.316860] perf_mmap+0x3bc/0x470 [ 337.316867] mmap_region+0x374/0x4f8 [ 337.316873] do_mmap+0x300/0x430 [ 337.316878] vm_mmap_pgoff+0xe4/0x110 [ 337.316884] ksys_mmap_pgoff+0xc0/0x230 [ 337.316892] __arm64_sys_mmap+0x28/0x38 [ 337.316899] el0_svc_common+0xb4/0x118 [ 337.316905] el0_svc_handler+0x2c/0x80 [ 337.316910] el0_svc+0x8/0xc [ 337.316915] ---[ end trace fa29167e20ef0c62 ]--- Let's avoid this by checking that the requested allocation is possible before calling kzalloc. Reported-by: Julien Thierry Signed-off-by: Mark Rutland Cc: Alexander Shishkin Cc: Ingo Molnar Cc: Jiri Olsa Cc: Namhyung Kim Cc: Peter Zijlstra --- kernel/events/ring_buffer.c | 3 +++ 1 file changed, 3 insertions(+) -- 2.11.0 Reviewed-by: Julien Thierry diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 4a9937076331..309ef5a64af5 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -734,6 +734,9 @@ struct ring_buffer *rb_alloc(int nr_pages, long watermark, int cpu, int flags) size = sizeof(struct ring_buffer); size += nr_pages * sizeof(void *); + if (order_base_2(size) >= MAX_ORDER) + goto fail; + rb = kzalloc(size, GFP_KERNEL); if (!rb) goto fail;