Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp4426377ybb; Tue, 7 Apr 2020 07:19:09 -0700 (PDT) X-Google-Smtp-Source: APiQypKG5XlyrW8UbTxSrQ01asGBUxnjmAtUrCm7CzxP2OnbW3H0MRYKxXM6MhYCApeTdfPxRjGz X-Received: by 2002:a05:6830:1313:: with SMTP id p19mr1809626otq.179.1586269149129; Tue, 07 Apr 2020 07:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586269149; cv=none; d=google.com; s=arc-20160816; b=lzER2hg4hevSa0LsXWkVnirACUsvhCOV5PnnuBj5ILrWFKdpPercvzmbD8OEMK1uqA +dlWD9reIkBV3frZ2P9vBLo+8Og4zwJun+Y9JBgdZOgpUsJupJMwbY9+nM3yfpSKalLr p9GYdjvdA9QCxqrt9hhyPhL2QjAt8lO4yGTRh3MaZeXPgnSYH0fRR6uBoRhalhDtf8DT 8TWzVEPdpCsQ4tGFYQZOV14+n/w4XXH30erOaFyul4iyusY5c1MsWvYbsFb/w0fmazeU 9/xhMKD0WbgQCU6AubX1MMqkTV67fu26AQVFchDVScYF8NCV6bj2xUfpiATHlppvayBV 96Hw== 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 :message-id:date:subject:cc:to:from; bh=QP8neIaTyad1/fCKXY+zDRc8u9iddSiEQfrRu0nTcYQ=; b=l/Y5AsVmg7tYduLB2oOZ5kBdt5hTJSdWobX+DlZxH8mTzvTcBJTsiecz9pFhAvXcYF nofp/vqjsfxK5pWE/l2vudJSi9TE4qYUGL8n9uIqorlI1VDda6EarBWS0j0DTQlI6j+5 D0qAo5Tt47jhLKiX5mnNKxihoij7n97tIH/P1ButIbo5zBkwhrT088sJsnC+/pfN7LMD otieoD47KPFaC+EeuXLgmR+JCaUT2oqt69m4iwNrosp6XX0zd5aFEzrcjAA3ODAHuD7I RtvMLQavLMGZhzEUsWmgc04t5Drr7mG6mKCw3GWcvNhLoSeeZ9ZtIGDGZKbi/pd0hKx3 +mnw== 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c26si1349161ooe.30.2020.04.07.07.18.50; Tue, 07 Apr 2020 07:19:09 -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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728997AbgDGOSH convert rfc822-to-8bit (ORCPT + 99 others); Tue, 7 Apr 2020 10:18:07 -0400 Received: from us-smtp-1.mimecast.com ([207.211.31.81]:58942 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728596AbgDGOSH (ORCPT ); Tue, 7 Apr 2020 10:18:07 -0400 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-453-6l2qDtB8Poe7U4226j9T-g-1; Tue, 07 Apr 2020 10:14:33 -0400 X-MC-Unique: 6l2qDtB8Poe7U4226j9T-g-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D7C36800D5C; Tue, 7 Apr 2020 14:14:31 +0000 (UTC) Received: from krava.redhat.com (unknown [10.40.192.7]) by smtp.corp.redhat.com (Postfix) with ESMTP id B74315DA60; Tue, 7 Apr 2020 14:14:28 +0000 (UTC) From: Jiri Olsa To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo Cc: Kan Liang , Madhavan Srinivasan , Peter Zijlstra , lkml , Ingo Molnar , Alexander Shishkin , Mark Rutland , Michael Petlan , Namhyung Kim Subject: [PATCH] perf: Disable page faults when getting phys address Date: Tue, 7 Apr 2020 16:14:27 +0200 Message-Id: <20200407141427.3184722-1-jolsa@kernel.org> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: kernel.org Content-Type: text/plain; charset=WINDOWS-1252 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We hit following warning when running tests on kernel compiled with CONFIG_DEBUG_ATOMIC_SLEEP: WARNING: CPU: 19 PID: 4472 at mm/gup.c:2381 __get_user_pages_fast+0x1a4/0x200 CPU: 19 PID: 4472 Comm: dummy Not tainted 5.6.0-rc6+ #3 RIP: 0010:__get_user_pages_fast+0x1a4/0x200 ... Call Trace: perf_prepare_sample+0xff1/0x1d90 perf_event_output_forward+0xe8/0x210 __perf_event_overflow+0x11a/0x310 __intel_pmu_pebs_event+0x657/0x850 intel_pmu_drain_pebs_nhm+0x7de/0x11d0 handle_pmi_common+0x1b2/0x650 intel_pmu_handle_irq+0x17b/0x370 perf_event_nmi_handler+0x40/0x60 nmi_handle+0x192/0x590 default_do_nmi+0x6d/0x150 do_nmi+0x2f9/0x3c0 nmi+0x8e/0xd7 While __get_user_pages_fast is IRQ-safe it calls access_ok, which warns on: WARN_ON_ONCE(!in_task() && !pagefault_disabled()) Peter suggested disabling page faults around __get_user_pages_fast, which gets rid of the warning in access_ok call. Cc: Kan Liang Cc: Madhavan Srinivasan Suggested-by: Peter Zijlstra Signed-off-by: Jiri Olsa --- kernel/events/core.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 1569979c8912..ccbcb9049c70 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -6916,9 +6916,12 @@ static u64 perf_virt_to_phys(u64 virt) * Try IRQ-safe __get_user_pages_fast first. * If failed, leave phys_addr as 0. */ - if ((current->mm != NULL) && - (__get_user_pages_fast(virt, 1, 0, &p) == 1)) - phys_addr = page_to_phys(p) + virt % PAGE_SIZE; + if (current->mm != NULL) { + pagefault_disable(); + if (__get_user_pages_fast(virt, 1, 0, &p) == 1) + phys_addr = page_to_phys(p) + virt % PAGE_SIZE; + pagefault_enable(); + } if (p) put_page(p); -- 2.18.2