Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp841070yba; Fri, 3 May 2019 11:19:16 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxBJiCk0UhHiWe/Iow62q8OkxFehWuxE9qjinITzfjNvfBwDysCB1vctbFuDNU9FLMRqLx X-Received: by 2002:a63:5720:: with SMTP id l32mr12618134pgb.438.1556907556435; Fri, 03 May 2019 11:19:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556907556; cv=none; d=google.com; s=arc-20160816; b=yAEjlMpeTT8TYZ8MF0+LnGscri9VDXpihZYHunqboo9/Ql2Ju2S6YEKsVNSSp2fhg9 /obaIG9dEv1bPv3BIwcb/P4iofFP5WqSl9wxOqKwhFeqJzdDpCaBTr2PmtDzfEbtNMe1 LcAIU90e/IB1ucWUzDq5k3oxxst8R2y88eTAc7BihiueGjkN+tHThxS1aF/QgcBQjL8E riPN9K6SdJkOT59MePru/PNFibPtMcTCZVRIHTJmDn5lBVMmiqqeinbz0gNNW4YXhXft Q5tNpRVFfwJhFwyqpsLlxgMXs0dbNeB+KptMujRRW9LHcpcjU1s7j7obByYiv4857xLa rw8w== 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=Go46w9TUnDBJU99iQ2zOx7oPmzF3Z8lvXzzfPdYzQf0=; b=soMVgR8gUpdVwwHQ8/9eTM3Gjc9EgEUzUU0/9HcWptqfHD/kLvpwwKKs6+p5toZUeI awTsLVF8Zc7/eK30gqjN2jksSthlgyCMlQyDwXppiG0AbW8Uck6/pmFOL04jWTxXWcHd L4/vEhrkj0eQkm+vKtGeCuTqY9rOqhDRtNgzjSL3sK1qb6PgqqpdedpjwI/ErijF8D+L 4yuLNE9ty8jGjZmx1FfriItPjPo6frojtJqtcaczq3eAGG+PmYvHafoe4z7NS2b+srt/ QmKijeZ5I10fVy7AFb1vNl+n93lCF5Tcc/em3ayNPbfA9aomoSXFgCXQt24RKVoacQpJ Xo0A== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b23si3343498pls.430.2019.05.03.11.19.00; Fri, 03 May 2019 11:19:16 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728073AbfECSMP (ORCPT + 99 others); Fri, 3 May 2019 14:12:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55710 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726992AbfECSMP (ORCPT ); Fri, 3 May 2019 14:12:15 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C9A08369CA; Fri, 3 May 2019 18:12:14 +0000 (UTC) Received: from jsavitz.bos.com (dhcp-17-237.bos.redhat.com [10.18.17.237]) by smtp.corp.redhat.com (Postfix) with ESMTP id 02AB960BFC; Fri, 3 May 2019 18:12:07 +0000 (UTC) From: Joel Savitz To: linux-kernel@vger.kernel.org Cc: Joel Savitz , Thomas Gleixner , Ingo Molnar , Masami Hiramatsu , Waiman Long , Mauro Carvalho Chehab , Kristina Martsenko , Andrew Morton , Cyrill Gorcunov , Kees Cook , "Gustavo A. R. Silva" , YueHaibing , Micah Morton , Yang Shi , Jann Horn , Alexey Dobriyan , Rafael Aquini , Michael Kerrisk , Yury Norov , David Laight Subject: [PATCH v3 0/2] sys/prctl: expose TASK_SIZE value to userspace Date: Fri, 3 May 2019 14:10:19 -0400 Message-Id: <1556907021-29730-1-git-send-email-jsavitz@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 03 May 2019 18:12:15 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the mainline kernel, there is no quick mechanism to get the virtual memory size of the current process from userspace. Despite the current state of affairs, this information is available to the user through several means, one being a linear search of the entire address space. This is an inefficient use of cpu cycles. A component of the libhugetlb kernel test does exactly this, and as systems' address spaces increase beyond 32-bits, this method becomes exceedingly tedious. For example, on a ppc64le system with a 47-bit address space, the linear search causes the test to hang for some unknown amount of time. I couldn't give you an exact number because I just ran it for about 10-20 minutes and went to go do something else, probably to get coffee or something, and when I came back, I just killed the test and patched it to use this new mechanism. I re-ran my new version of the test using a kernel with this patch, and of course it passed through the previously bottlenecking codepath nearly instantaneously. As such, I propose that the prctl syscall be extended to include the option to retrieve TASK_SIZE from the kernel. This patch will allow us to upgrade an O(n) codepath to O(1) in an architecture-independent manner, and provide a mechanism for future generations to do the same. Changes from v2: We now account for the case of 32-bit compat userspace on a 64-bit kernel More detail about the nature of TASK_SIZE in documentation Joel Savitz(2): sys/prctl: add PR_GET_TASK_SIZE option to prctl(2) prctl.2: Document the new PR_GET_TASK_SIZE option include/uapi/linux/prctl.h | 3 +++ kernel/sys.c | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) man2/prctl.2 | 10 ++++++++++ 1 file changed, 10 insertions(+) -- 2.18.1