Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp4665389ybc; Fri, 15 Nov 2019 08:10:52 -0800 (PST) X-Google-Smtp-Source: APXvYqxrlG631sAiZBXiOLChg9T51BW7vc32XZ6hUz8Yx+DN3UB+oB79j1AUBTOeGvwfEDVVxp+y X-Received: by 2002:a17:906:5959:: with SMTP id g25mr1877646ejr.248.1573834252638; Fri, 15 Nov 2019 08:10:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573834252; cv=none; d=google.com; s=arc-20160816; b=i78MXwuf3z+V2Bbbl63ynDzOo3gYbi6mTBkv0BZuvCDEMmeYKGGCfIZ9B08TBJZvm/ QEKiOfOeQUlZBDT+S15f77i3Gy6VKfUqbtzzFB1597QdIkuzKVM0Eyd0imoacUC8PaL3 vLLDVE6qyrfa+DAxIOpWTkAKTcAZZn9jDX6K4L+R0znPahOd7U1ujRH97FGpyT+Hp/xh hSgl+PwHKrnGJ/57GFEESLSoKyRc4Wp8T7/PDpr6+UJ2Ikqjcc61G26FtycJ+f7Pc0os I2mJAUz1W1jtPHqvEYNFGcZxIcrgfq0LePxuDAc8u35182RNu6Fka2obLNyFCycLMcBx hPQw== 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=/jjteYdvVeZsWXUJ1SGbIUlaTHkaY+PTZRfpwHhvaXw=; b=QIW4yo5F3PjIp4S9BwIW1ztmTrVof36/usDN5ngIS+0uDhwuTZHsXrTzR6u3mUt/sn shvmzmjRV2vGJ8uzojiJjkhBRbMHUAPl0Fu4Pv+c/FhrLFLr7KV19YA/sDIvVRYuT8uW mKifeFbvodOk31KT8L27YxkU76gKxsSVicxAKaLOo6+jS+xyNSxWsHTMfTKnLfnfnx+s kRfnvqnCK7bxOrjDfA9pDWUXHvPtPSFBak5kpqA/JdoEKQmr4TEu2Zgzjt7S4VKqmFuj wi6hjCkzxrEeeCCIdz0vCGB9AJGVRjgbhR+mU07d+O0RQ/tpK6OV240AgP6gSm0xT4z3 EQrA== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t18si6148607eji.130.2019.11.15.08.10.27; Fri, 15 Nov 2019 08:10:52 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727607AbfKOQI3 (ORCPT + 99 others); Fri, 15 Nov 2019 11:08:29 -0500 Received: from mga11.intel.com ([192.55.52.93]:21438 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfKOQI3 (ORCPT ); Fri, 15 Nov 2019 11:08:29 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 15 Nov 2019 08:08:29 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,308,1569308400"; d="scan'208";a="405377086" Received: from black.fi.intel.com (HELO black.fi.intel.com.) ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 15 Nov 2019 08:08:26 -0800 From: Alexander Shishkin To: Peter Zijlstra Cc: Ingo Molnar , linux-kernel@vger.kernel.org, tmricht@linux.ibm.com, Alexander Shishkin Subject: [PATCH] perf: Fix the mlock accounting, again Date: Fri, 15 Nov 2019 18:08:18 +0200 Message-Id: <20191115160818.6480-1-alexander.shishkin@linux.intel.com> X-Mailer: git-send-email 2.24.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 5e6c3c7b1ec2 ("perf/aux: Fix tracking of auxiliary trace buffer allocation") tried to guess the correct combination of arithmetic operations that would undo the AUX buffer's mlock accounting, and failed, leaking the bottom part when an allocation needs to be changed partially to both user->locked_vm and mm->pinned_vm, eventually leaving the user with no locked bonus: $ perf record -e intel_pt//u -m1,128 uname [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.061 MB perf.data ] $ perf record -e intel_pt//u -m1,128 uname Permission error mapping pages. Consider increasing /proc/sys/kernel/perf_event_mlock_kb, or try again with a smaller value of -m/--mmap_pages. (current value: 1,128) Fix this by subtracting both locked and pinned counts when AUX buffer is unmapped. Signefdoff-by: Alexander Shishkin --- kernel/events/core.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kernel/events/core.c b/kernel/events/core.c index 16d80ad8d6d7..522438887206 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5664,10 +5664,8 @@ static void perf_mmap_close(struct vm_area_struct *vma) perf_pmu_output_stop(event); /* now it's safe to free the pages */ - if (!rb->aux_mmap_locked) - atomic_long_sub(rb->aux_nr_pages, &mmap_user->locked_vm); - else - atomic64_sub(rb->aux_mmap_locked, &vma->vm_mm->pinned_vm); + atomic_long_sub(rb->aux_nr_pages - rb->aux_mmap_locked, &mmap_user->locked_vm); + atomic64_sub(rb->aux_mmap_locked, &vma->vm_mm->pinned_vm); /* this has to be the last one */ rb_free_aux(rb); -- 2.24.0