Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp87649yba; Fri, 3 May 2019 21:25:12 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVahdSDKLPaTceSLcnWeLcMOoquzJk/J8g+AW4r5X0ImQJwHI5cflY2/IJlwtGkj2egoE7 X-Received: by 2002:a65:6656:: with SMTP id z22mr15546636pgv.333.1556943912651; Fri, 03 May 2019 21:25:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556943912; cv=none; d=google.com; s=arc-20160816; b=pxLgj2vKCxKVPzG4d5CHXhUobz89CEB1mEe/apf0gt+iCxKFi6FmOa53R/JVZdlEw8 iXFwo3E50Ik/z4I+HfTA51mVDs2EyVtLDdHsK5NzxpDtj/skY9SrCX4B8TOc/oiMwokP MLcjyfms204Pn3/6tcZkZatd6G12zahPDCDpRXM9auHyYfSqyxh2VrPcZw6ZIeNsjVmA b07uHGn3/b1S3gdOzmBdltSj95nBskGgaLL8fKzqPFKqYgEZDseJp+ReBfhW+an+dqwY stBjN2rwm0SytgJ6CY7Iovw8mlcUFPk198H+YPsVAEAk397nXIgL+o5ECu82yFtO5Hfl CVTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Gt01AfOetDzcKf21xssimOsxGdNcsgRMqPBrhJOYNzE=; b=mRl1nslxpb5h5a/qyC7Csme/41Tbetey5uIVG8UI1p4NWhLqhWoVodNR0U01CBdL6/ 9f0kwRzV1jj/ld9TavGW82OF3BlzivTS7IGbFDKkRT/iFcc8aXYNQ5KO1s96eY5iJp1k SPabO+snMEiNKUTByeilQyE9E18KxgeImMAllnp0m0icFaClN5EpFAHNCigzY8WPwHsh qyJjEAt82WkfSkgUk/FlsMWX4lKaziIb+eEc45gdCezjsa8WsUrZl1MdC1N/9gBdvRnk yohcR3fyZHCODUqmVm6W9Y0lGqUpBQGWpcfDAMsyCfnYZCSIMYQm9E/pPgpIDD457fG0 nNfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eOfl1eEE; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r23si4945528pgv.471.2019.05.03.21.24.57; Fri, 03 May 2019 21:25:12 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eOfl1eEE; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726604AbfEDEVp (ORCPT + 99 others); Sat, 4 May 2019 00:21:45 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:41822 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725770AbfEDEVo (ORCPT ); Sat, 4 May 2019 00:21:44 -0400 Received: by mail-pl1-f195.google.com with SMTP id d9so3658460pls.8 for ; Fri, 03 May 2019 21:21:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Gt01AfOetDzcKf21xssimOsxGdNcsgRMqPBrhJOYNzE=; b=eOfl1eEEVF0oWu8cAyXB2JksYkfWv3I2Xdt1iddeZviy+41P+3a82jGGDvsvsm72hx e0hTUozh4BcA0FXITK6wR1UIUyK9uf9X/0NQ4iI2uMUTIvCX+DqOtpbvD2zWiobFvdcM 1MUbWi9RyaSLgmSvYzeV5BkPWo3iAtdvzVELt+bz3Rc7ME5Yfk+8SYMraKvoHgIVxGkX DeLpIR4H+CDL7nPxX42cP8cm6cOfmTal7KXnyA0xBRb0iaMt0+YUCu8DCvKBZ4+yc5CI fpnE1czINVDd08K5kOSHIumwLLVh/YNpSPmI0QTI1eip7uCpkXeMdAdyu3Fxx+bElhX6 L1Fw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Gt01AfOetDzcKf21xssimOsxGdNcsgRMqPBrhJOYNzE=; b=gBTE2INcJeYgxCF0oQvH34CQTkO3NHxKVCFcwkaXxtQ1rvBhXLxmsuvmCfprUeDYRG 8ksnb7+TApYkGp5CMp6q3PexJYBLLEnoKH9Oz1VIa1dnyz1nmaWJ8CHly4m562ld7yEb iLO09KnxRR0aBPlFqCn1mme7qVlZeZ0dTLcgPyFyj4ebpLkGSn9P+VYSGXvOAuXL8TJ7 GXivGWHU8EqR1wJiRgyj0x5keY/vOKA1/gx9TMyk6BhDZWKiDweMWVbho+Dc4gL0Gtmy qa1VlHUuttitn0zGk+BzL/CHcc9aIpc3Yluvuptd1YKGinrcYOD3Hf1rGWIS3hvhQBaH EDTw== X-Gm-Message-State: APjAAAWRtK3rwchOAV2UfEivszYuCIAwRkSNdyussueILV0kfuD8S4oU DQGmD1pI+gMKFZHG/jkFHk4= X-Received: by 2002:a17:902:7611:: with SMTP id k17mr16083398pll.30.1556943703221; Fri, 03 May 2019 21:21:43 -0700 (PDT) Received: from localhost ([2601:640:d:fe8a:ec58:f256:b33e:bd28]) by smtp.gmail.com with ESMTPSA id d126sm5225970pfc.96.2019.05.03.21.21.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 May 2019 21:21:42 -0700 (PDT) Date: Fri, 3 May 2019 21:21:41 -0700 From: Yury Norov To: Rafael Aquini Cc: Joel Savitz , linux-kernel@vger.kernel.org, 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 , Michael Kerrisk , David Laight Subject: Re: [PATCH v3 0/2] sys/prctl: expose TASK_SIZE value to userspace Message-ID: <20190504042141.GA12920@yury-thinkpad> References: <1556907021-29730-1-git-send-email-jsavitz@redhat.com> <20190503204912.GA5887@yury-thinkpad> <20190503215731.GB10302@x230.aquini.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190503215731.GB10302@x230.aquini.net> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 03, 2019 at 05:57:31PM -0400, Rafael Aquini wrote: > On Fri, May 03, 2019 at 01:49:12PM -0700, Yury Norov wrote: > > On Fri, May 03, 2019 at 02:10:19PM -0400, Joel Savitz wrote: > > > 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. > > > > So the only reason for the new API is boosting some random poorly > > written userspace test? Why don't you introduce binary search instead? > > > > there's no real cost in exposing the value that is known to the kernel, Really? We all here used to think that kernel programming is one of the most difficult professions in the world. There is huge cost of proper implementation of a feature, careful review, spread testing on various platforms and long-term maintenance and support. In this specific example of exposing TASK_SIZE your team made too much things wrong to realize it, I hope. > anyways, as long as it's not a freaking hassle (like trying to go with > this prctl(2) stunt). We just need to get it properly exported alongside > other task's VM-related values at /proc//status. I found this thread thrilling. Please keep me in CC with your /proc//status effort. Yury > > Look at /proc//maps. It may help to reduce the memory area to be > > checked.