Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp225103ima; Thu, 31 Jan 2019 15:28:01 -0800 (PST) X-Google-Smtp-Source: AHgI3Ibp5UavEf8TFYL6xK1csXAi+sIzd4UirlpRgBa1kFWzdBN7d4Ky5dakU3Q8bordVjgt53fX X-Received: by 2002:a63:2a44:: with SMTP id q65mr1032002pgq.231.1548977281179; Thu, 31 Jan 2019 15:28:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548977281; cv=none; d=google.com; s=arc-20160816; b=lJSXBvHPexVWZEEUm+ot+YCrG11goawyiSbqhTjj5vB/cT8i1KuPIpOrJ1qSupXqcL jaBFb7LOonoIYHF1u2ECfd4JfjWl4FB0Nj5tJlpwvjoP6yt5sRa4H8l6fTMhjpx3Y92L POU6KzwueDGR/F02XWDnxWG4XM/AwmxK2pLy3veOXUZGHYBQZxNkqSQShp2WzAeNGbIl HaCi9bB8KCAQPHc/a6l8b/gcFsgDMeh08LX+djemSb9KoaTLjqIlx5ztHCbLbnHpJmdh 3rfTV60incT5Gxy74PxahlYAfz6cFcnWku4IYMnAvUHI4ciAjv709WE5/waRaU6c35aq B08g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=tkiv142AtR3mKFcfGs97SC15vyGtXkrw/acP+pBqHzw=; b=LyAplip1HTKqWO2cO0REAiMNyoNCtPJMIq62SfMBgXlabwHrr+AIrsZPez+VFdyEdv JRr16sKc+49LVzGA3GJipFjPfLi+EMFygWFHvpo7LB6cIncWe9vzELICCaRnNgZCVtNe ptB5quStHigJxSlUrkEAksP+GaSpr1hi8Q299pJcCBOVVDWwuH+ABMpSceuo2BuPjAV2 4FqjY9WbcO73yfjZU3fqVOjGz1KtuJG1nYZOVWL3bjKofwFr7DMoHjBPLGT6tYS93PmX zmOoWyyJZH0Em3PkzN6xT8YZ5YSmA09N/9/ozQ2YdMbgNUqxHdNEf+iZf7mwVjwAB7x0 htBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=iU3QdGkv; 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=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 37si5117473pgw.590.2019.01.31.15.27.46; Thu, 31 Jan 2019 15:28:01 -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; dkim=pass header.i=@chromium.org header.s=google header.b=iU3QdGkv; 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=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727237AbfAaWtU (ORCPT + 99 others); Thu, 31 Jan 2019 17:49:20 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:53148 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725775AbfAaWtT (ORCPT ); Thu, 31 Jan 2019 17:49:19 -0500 Received: by mail-it1-f193.google.com with SMTP id d11so6426413itf.2 for ; Thu, 31 Jan 2019 14:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=tkiv142AtR3mKFcfGs97SC15vyGtXkrw/acP+pBqHzw=; b=iU3QdGkv4AxS48U/SOmzRyyCIdzZxnS1g5kI8E4/99+MSd23lPZJaa6yd4sELSXgYO AvNNVVEtBu5nRVvVh2INjDsQLz07xJ2x3MVS/oOLaFQocayuDpfXkFHS02G+CO4q9EFl akIvTXBoQWXcqEG87LUsRSvBNtAU0Y/6XYOGQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=tkiv142AtR3mKFcfGs97SC15vyGtXkrw/acP+pBqHzw=; b=Y6ATOlsODnikz53ZVkPWDASHbDE1I151HxzfQHDoJ1HSqvJVU9TTfi8IxmmcWVxn3e rIm98tV6B48MwG1Xm+mQdDgp8Xy3NmsHDKj2h6GOiYATVXz9VP8B+w0ctxNvVSJLIu3w NaWoO9c19IHF79VPhGy0DNHUe+wjso2jo7QEx9g18/xdJr7fGsVVCN35zHYWB42L1sWW rKyP7zPNPl2JRHAlFZV5NS6e9Zb2S5UYVvmNWX2dsNZHh0xzIM7kbFqYDouTwxJu6Nz1 v2fYuKHwwtLofBtG0BeaXdmzGplU1tb+UiOw7GYxcMooHffOlPNa3CJVNIDKdthMMMQ1 FfcA== X-Gm-Message-State: AHQUAuZpEyjxd6y0AdnJTY9GtDyWZT++wrJiZkW7WF351MMye3nGY1HY Hu74xWYJOPcANVS94LxJ1a9kt3jbBKQ= X-Received: by 2002:a24:a64f:: with SMTP id r15mr8102118iti.101.1548974958623; Thu, 31 Jan 2019 14:49:18 -0800 (PST) Received: from mail-it1-f173.google.com (mail-it1-f173.google.com. [209.85.166.173]) by smtp.gmail.com with ESMTPSA id x128sm365382itb.8.2019.01.31.14.49.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 31 Jan 2019 14:49:18 -0800 (PST) Received: by mail-it1-f173.google.com with SMTP id g85so6414782ita.3 for ; Thu, 31 Jan 2019 14:49:17 -0800 (PST) X-Received: by 2002:a24:d081:: with SMTP id m123mr19889982itg.119.1548974956119; Thu, 31 Jan 2019 14:49:16 -0800 (PST) MIME-Version: 1.0 References: <20190131192533.34130-1-thgarnie@chromium.org> <20190131192533.34130-15-thgarnie@chromium.org> <01000168a5b35a86-b79bfe67-191e-43bc-a5c7-0e74eac06195-000000@email.amazonses.com> In-Reply-To: <01000168a5b35a86-b79bfe67-191e-43bc-a5c7-0e74eac06195-000000@email.amazonses.com> From: Thomas Garnier Date: Thu, 31 Jan 2019 14:49:04 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 14/27] x86/percpu: Adapt percpu for PIE support To: Christopher Lameter Cc: Kernel Hardening , kristen@linux.intel.com, Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "the arch/x86 maintainers" , Dennis Zhou , Tejun Heo , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Andrew Morton , Andi Kleen , "Kirill A. Shutemov" , Michal Hocko , Mike Rapoport , Stephen Rothwell , Cao jin , Brijesh Singh , Masahiro Yamada , Joerg Roedel , Peter Zijlstra , Kees Cook , Mathieu Desnoyers , LKML , xen-devel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 31, 2019 at 12:57 PM Christopher Lameter wrote: > > On Thu, 31 Jan 2019, Thomas Garnier wrote: > > > Perpcu uses a clever design where the .percu ELF section has a virtual > > address of zero and the custom linux relocation code avoid relocating > > specific symbols. It makes the code simple and easily adaptable with or > > without SMP support. > > We usually talk about this as offsets rather than addressess. The intend > here is to give every processor its own address that is unique for this > processor. Operations are always relative to a segment register and the > whole area can be relocated at will by simply changing the segment > register. > > > This design is incompatible with PIE. While creating a PIE binary, the > > copmiler tries to make everything relative. The compiler will attempt to > > This is very compatible with PIE because it is already relative. The per-cpu symbols are in a section that is zero based to create offsets. The compiler doesn't see them as offsets but as relative symbol and try to relocate them. Given the distance between zero and the mapped kernel is much larger than the instruction offset range, it fails to do it. > > > generate instructions with the distance between zero and any 64-bit > > virtual address. It will fail as the relocation range cannot fit within > > the possible instructions accessing a segment register. > > Leave the offsets alone and just change the segment register if you need > to relocate the area of a specific processor? > > > The assembly and PER_CPU macros are changed to use relative references > > when PIE is enabled. > > They already use relative reference. What is the point here? > > > --- a/arch/x86/include/asm/percpu.h > > +++ b/arch/x86/include/asm/percpu.h > > @@ -5,9 +5,11 @@ > > #ifdef CONFIG_X86_64 > > #define __percpu_seg gs > > #define __percpu_mov_op movq > > +#define __percpu_rel (%rip) > > The percpu section cannot be IP relative since we need to have separate > address spaces per cpu. >