Received: by 2002:a05:6602:2086:0:0:0:0 with SMTP id a6csp4411733ioa; Wed, 27 Apr 2022 03:20:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwE0gmHuZLPckPQrIvwmc1Is+2JTDi/Yj+fqaUYfzYpIdK+u9qLFvVQD0X6Hpqt55pWWjAg X-Received: by 2002:a17:90b:1801:b0:1d2:6382:dfe4 with SMTP id lw1-20020a17090b180100b001d26382dfe4mr32092702pjb.202.1651054819778; Wed, 27 Apr 2022 03:20:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651054819; cv=none; d=google.com; s=arc-20160816; b=zLovSVhbof0RDuojy+UXxgy6pvuzIl9HeoJWaDJJRUe5ncCmKd87JyizC/H/dkPn2C LNxc+Oi6YDCXRnh/1vS7AnEj5JrO+V46mTTOp9QI/H2gn+ZCHQOcG3PUdsXXBML7PWBy STigu+MRf22DmBB2o4ZnRDCPbXcs7DoC+qFTnfMOs6/RWf58d4fxsctkcFeKARqsM+CF AO2KIhUwTSMgGpOEMyJkPX3fIQp0IokMjW8kE+0aq41vhsN8XT4/5r3x70xWG7DyrCyF kDud5NPgheRJHjv+W5o/05fqKvMwnJ9lpCzJ7Bjb7x/IMvcLkAkrq5Bxv8DyegaVriLW 4CMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=O/++Grp8DooYd+vPOwc/bMM0IQCq8hbjIobVIkn7Bxk=; b=sg6mauyiEf9NSQA5kNvvYvDZIT0/5M0/P3tTB6YgZQ6VqR1QaRZUDgJCW3oUqnkkyl YqQ5zyOUYaejAtmxEnEELegLNAAl3f6nzVBcNqEmdqeW4NDQ1LJasxIFqqYcjiS1SIAx +tRRsvqzGa+88ElDlETjfLaoP1ck7UHVhCX2OpraT2jTXQrG02rtnP2VwSIePEe9K295 OomLSYyh5/sHl2wG9udEzhtIUfjtdFQweOfNO3YLU+7tqjyCNuSFdfvGsiDKqtC8pCa8 zNUhgPETFOO7cnqUNIu9wOt/llVQL+9b7g9CUCgvk3kbhViSCzMUkPt4PsFd3l0LVVKT tf8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="o5TEQ/jU"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id g8-20020a170902d5c800b0015d31963594si1172595plh.291.2022.04.27.03.20.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Apr 2022 03:20:19 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="o5TEQ/jU"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C51E4362521; Wed, 27 Apr 2022 02:39:54 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348128AbiDZJjC (ORCPT + 99 others); Tue, 26 Apr 2022 05:39:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346502AbiDZJIX (ORCPT ); Tue, 26 Apr 2022 05:08:23 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D2ED13FB8; Tue, 26 Apr 2022 01:49:14 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E1A65B81D09; Tue, 26 Apr 2022 08:49:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 42404C385BE; Tue, 26 Apr 2022 08:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1650962951; bh=3cOjFrytvu+eMwtQ4tbOjqFmZep/na2RTLi1ivZ+4d4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=o5TEQ/jU720560Mnex5Ld1dO38H7ynSa0WZijPU6b4tnGV1cfbBxpAR9spWMqHBHP qSsklAV1mAcfRziBZ7tjO3LJqUrZrQQzNxjj+xZXds0/PVsWlU+BFl25CyfuZFlrcn oEfJVVI64NNAWcmXC6XozZM/blEME0cPUKSfQNYU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhipeng Xie , "Peter Zijlstra (Intel)" , Sasha Levin Subject: [PATCH 5.17 103/146] perf/core: Fix perf_mmap fail when CONFIG_PERF_USE_VMALLOC enabled Date: Tue, 26 Apr 2022 10:21:38 +0200 Message-Id: <20220426081752.954011534@linuxfoundation.org> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220426081750.051179617@linuxfoundation.org> References: <20220426081750.051179617@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhipeng Xie [ Upstream commit 60490e7966659b26d74bf1fa4aa8693d9a94ca88 ] This problem can be reproduced with CONFIG_PERF_USE_VMALLOC enabled on both x86_64 and aarch64 arch when using sysdig -B(using ebpf)[1]. sysdig -B works fine after rebuilding the kernel with CONFIG_PERF_USE_VMALLOC disabled. I tracked it down to the if condition event->rb->nr_pages != nr_pages in perf_mmap is true when CONFIG_PERF_USE_VMALLOC is enabled where event->rb->nr_pages = 1 and nr_pages = 2048 resulting perf_mmap to return -EINVAL. This is because when CONFIG_PERF_USE_VMALLOC is enabled, rb->nr_pages is always equal to 1. Arch with CONFIG_PERF_USE_VMALLOC enabled by default: arc/arm/csky/mips/sh/sparc/xtensa Arch with CONFIG_PERF_USE_VMALLOC disabled by default: x86_64/aarch64/... Fix this problem by using data_page_nr() [1] https://github.com/draios/sysdig Fixes: 906010b2134e ("perf_event: Provide vmalloc() based mmap() backing") Signed-off-by: Zhipeng Xie Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20220209145417.6495-1-xiezhipeng1@huawei.com Signed-off-by: Sasha Levin --- kernel/events/core.c | 2 +- kernel/events/internal.h | 5 +++++ kernel/events/ring_buffer.c | 5 ----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 0ee9ffceb976..baa0fe350246 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6352,7 +6352,7 @@ static int perf_mmap(struct file *file, struct vm_area_struct *vma) again: mutex_lock(&event->mmap_mutex); if (event->rb) { - if (event->rb->nr_pages != nr_pages) { + if (data_page_nr(event->rb) != nr_pages) { ret = -EINVAL; goto unlock; } diff --git a/kernel/events/internal.h b/kernel/events/internal.h index 082832738c8f..5150d5f84c03 100644 --- a/kernel/events/internal.h +++ b/kernel/events/internal.h @@ -116,6 +116,11 @@ static inline int page_order(struct perf_buffer *rb) } #endif +static inline int data_page_nr(struct perf_buffer *rb) +{ + return rb->nr_pages << page_order(rb); +} + static inline unsigned long perf_data_size(struct perf_buffer *rb) { return rb->nr_pages << (PAGE_SHIFT + page_order(rb)); diff --git a/kernel/events/ring_buffer.c b/kernel/events/ring_buffer.c index 52868716ec35..fb35b926024c 100644 --- a/kernel/events/ring_buffer.c +++ b/kernel/events/ring_buffer.c @@ -859,11 +859,6 @@ void rb_free(struct perf_buffer *rb) } #else -static int data_page_nr(struct perf_buffer *rb) -{ - return rb->nr_pages << page_order(rb); -} - static struct page * __perf_mmap_to_page(struct perf_buffer *rb, unsigned long pgoff) { -- 2.35.1