Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3116052yba; Mon, 22 Apr 2019 20:25:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxwaisfC/g+ROzPDmTFcZFjb1sbH/uI8zudGeyhUSSwG0AAQPw10s/RdTzVLpGClg5QU3Rn X-Received: by 2002:a17:902:7d8f:: with SMTP id a15mr23383404plm.3.1555989908529; Mon, 22 Apr 2019 20:25:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555989908; cv=none; d=google.com; s=arc-20160816; b=en6KwNCpVPTBS236IymjYxBwMtet4zXAnRIx3xx8JtzBmXcjJENWD8+44wXTMjBsqz lhRy3lCHX4TblOeGj/06GRideC9OkwJe/gRUy1yy8XuIUyhF5ysfE4DOm9QLVopdf/Px C1Lb+ozHLdbZ8Y3HqrgcROdETpYc2ijNPTlbTjjj3qsZRgK4xAU5WGmxSMVHn3w+ujxB s0uRPuCsBk6WSJhNgo+S3NDOIzHjvMdqzjeI1MiAGUOlOOngU486BaG3hpYxfu+RCA9C Y0Vn03whVWxnRm13CQ7GnCdIDhwf1GYW8fdNm6QoVmEZSZMesZp0XAGlTg0Bt/tMoNoZ dsDQ== 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=U8XMOAbFPcRWzCl5EAqV4Jxp+w9p90qZdgQkYs5X0YU=; b=tvys52keAS9n0KFAd7wmjGoZPSh1tXxe0PKwESre6mnWsjyKIjxSH3l5ritu0kZMfo tKkM6ir2hm/JMgGPAw3SiwPz5VScgL0iUuFmAnN42J2v4177jgATgWIkeW7C4wXzoQux jMekdaN7kZzo1GLDhIMI7X0/PTHiDptm8xNpRrhLtfPg1XjfBbH7dx6JsNkpg51shb8E 2V1kCghrzjyD1sG2c04aHTQcZSP0kRQYw34Rt9EInsRm2xSAEdHX+7v1QXsNixC0kvtM NnVFIGDXfru4Tiip3hKkgUxaCS0FEz2pg+VHVC07o68vWjTtXayi6CWaMr3fizQHdQVP NcGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=cgYOR77C; 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 n11si12692762pgp.482.2019.04.22.20.24.38; Mon, 22 Apr 2019 20:25:08 -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=cgYOR77C; 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 S1730221AbfDVWJw (ORCPT + 99 others); Mon, 22 Apr 2019 18:09:52 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39423 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729165AbfDVWJw (ORCPT ); Mon, 22 Apr 2019 18:09:52 -0400 Received: by mail-wm1-f65.google.com with SMTP id n25so16068784wmk.4 for ; Mon, 22 Apr 2019 15:09:51 -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=U8XMOAbFPcRWzCl5EAqV4Jxp+w9p90qZdgQkYs5X0YU=; b=cgYOR77CmJ0Bo4MI2S8GjtP3DUSrs2t0/2VYAe7eX6U+aL7e1226i7xtpzsRaNvJHF lIJIW1KGyOD1OHROFf7Cr+RMuzEWAYN9qF8ST6bf94qL+LNTFiYV7mMXi1yMeuXIeECa pZ9rJ0oEQZfwGV35RvV7IHvzlT1nmVpLWlIeILCejvTTcw8lp43WqnyqjAscysW1KXEf oSRGb0r0pETy71sm4RkfkjJMcYYNrqG3MZ+UQ1iKKCp5n2TLuVBun2hHo7va9DyYuC7r B0rHzcHY+nJHOpgPzkVAIW5QzKuhlq31b+KfFslNsqe5QMARPJa1aNTg891NGy3VinnR V2sg== 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=U8XMOAbFPcRWzCl5EAqV4Jxp+w9p90qZdgQkYs5X0YU=; b=NM+IyLKIYYB81Jf8Gc6OI+pQOjKYchBN16HkVPl2Ss5Kl/9IEulIhqEExOiUOA0DxA gWV8t0mFgFD3GnA7tVqdk9WAVm61oj8832Hyhs0YYZfNchbpVSNhUY6+woILiYlxShES Tw3CNQEY9lbdr7XnwqTkAZ4dWtN3OxlSKuOvucTceAx15ZE2SfXxIO0WbDSofw4HFTzc F++xzX4FRZ3iXelKAqGxvZtCUMv0Exhqcg+myPtT+BM6yBZx+Ra6TIUtMtMEYXPMsyK9 DuD2h660sm1lQq0qHNVb5V6RKYON3ygWq1EPgx3usnZw/JzN7hRfGC1hUVwNfHaFkqJQ QAIw== X-Gm-Message-State: APjAAAUT7RIyJvIiXGSS+GJ6PqA82/x1XGZwNwZE/4uekltdN/8/zt/x 7RXZDhQ5aFoTla2StoZ1/Q== X-Received: by 2002:a1c:5f08:: with SMTP id t8mr230795wmb.65.1555970991210; Mon, 22 Apr 2019 15:09:51 -0700 (PDT) Received: from avx2 ([46.53.240.81]) by smtp.gmail.com with ESMTPSA id l19sm26366288wrf.35.2019.04.22.15.09.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Apr 2019 15:09:50 -0700 (PDT) Date: Tue, 23 Apr 2019 01:09:48 +0300 From: Alexey Dobriyan To: Andy Lutomirski Cc: Ingo Molnar , hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, linux-kernel@vger.kernel.org, x86@kernel.org, Andy Lutomirski , Peter Zijlstra , Linus Torvalds , Al Viro Subject: Re: [PATCH] x86_64: uninline TASK_SIZE Message-ID: <20190422220948.GB26031@avx2> References: <20190421160600.GA31092@avx2> <20190421182842.GD35603@gmail.com> <8B42CD57-9343-4234-A96D-80337BFFDF0E@zytor.com> <20190421211007.GA30444@avx2> <20190422103449.GA75723@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 22, 2019 at 07:30:40AM -0700, Andy Lutomirski wrote: > > > > On Apr 22, 2019, at 3:34 AM, Ingo Molnar wrote: > > > > > > * Alexey Dobriyan wrote: > > > >>>>> +++ b/arch/x86/kernel/task_size_64.c > >>>>> @@ -0,0 +1,9 @@ > >>>>> +#include > >>>>> +#include > >>>>> +#include > >>>>> + > >>>>> +unsigned long _task_size(void) > >>>>> +{ > >>>>> + return test_thread_flag(TIF_ADDR32) ? IA32_PAGE_OFFSET : > >>>> TASK_SIZE_MAX; > >>>>> +} > >>>>> +EXPORT_SYMBOL(_task_size); > >>>> > >>>> Good idea - but instead of adding yet another compilation unit, why not > >>>> > >>>> stick _task_size() into arch/x86/kernel/process_64.c, which is the > >>>> canonical place for process management related arch functions? > >>>> > >>>> Thanks, > >>>> > >>>> Ingo > >>> > >>> Better yet... since TIF_ADDR32 isn't something that changes randomly, > >>> perhaps this should be a separate variable? > >> > >> Maybe. I only thought about putting every 32-bit related flag under > >> CONFIG_COMPAT to further eradicate bloat (and force everyone else to > >> keep an eye on it, ha-ha). > > > > Basically TIF_ADDR32 is only set for a task if set_personality_ia32() is > > called, which function is called in the following circumstances: > > > > - arch/x86/ia32/ia32_aout.c:load_aout_binary() > > > > This is in exec(), when a new binary is loaded for the current task, > > via search_binary_handler() and exec_binprm(). Ordering is > > synchronous, AFAICS there can be no race between TASK_SIZE users and > > the set_personality_ia32() call which is always for the current task. > > > > - in COMPAT_SET_PERSONALITY(), which through macro detours ends up being > > in SET_PERSONALITY2(), which is used in fs/compat_binfmt_elf.c's > > load_elf_binary(), used in a similar fashion in exec() as the AOUT > > case above. One particular macro detour of note is that > > fs/compat_binfmt_elf.c #includes fs/binfmt_elf.c and re-defines the > > personality setting method to map to set_personality_ia32(). > > > > When set_personality_ia32() is called then TIF_ADDR32 is set > > unconditionally, without any Kconfig variations. > > > > TIF_ADDR32 is cleared: > > > > - In set_personality_64bit(), when a 64-bit binary is loaded via > > fs/binfmt_elf.c. > > > > - It also defaults to clear in the init task, which is inherited by the > > initial kernel threads and any user-space task they might end up > > executing. > > > > So the conclusion is that IMO we can safely put TASK_SIZE into a new > > thread_info()->task_size field, and: > > > > - change ->task_size to the 32-bit address space in > > set_personality_ia32() > > > > - change ->task_size to teh 64-bit address space in the init task and in > > set_personality_64bit(). > > > > This should cover it I think, unless I missed something. > > > > Are there really enough TASK_SIZE users to justify any of this? Saving 2KB on a defconfig is quite a lot. If put into thread_info, ->task_size can be pulled using just RAX which in turn allows to do asm volatile "call %P" ... "=a" (...) saving even more space. But it is late here so don't quote me.