Received: by 2002:ac0:8c9a:0:0:0:0:0 with SMTP id r26csp185801ima; Thu, 31 Jan 2019 14:41:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN4zJJO2iBxLvcX95w4s749bNiOMtKcJ27L04bXWbL6z9kXJc3kWdwev4xohz7mKE6c4zqO7 X-Received: by 2002:a63:f444:: with SMTP id p4mr32891544pgk.124.1548974471490; Thu, 31 Jan 2019 14:41:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548974471; cv=none; d=google.com; s=arc-20160816; b=DDOhXGYtMvr9pfo3+4lnESQSESK3kKNn/WhoYKFHgPkgXssN7gulJl4C1kr7mZEELz XLZ0a20UHtQNdgs2W6oMq3MADI2E5xByobaUNfAKfN/bD++J+Nbt5+vioqQNAUtv1pd8 ZIFfRIzBj0UKQ+kar93AQ23jXtvi7kYy0gIxMyUFKpxKBNqwlOeJdFAZDfuJhKKxjaO1 Yqr3B2XJ/yZ6swi+5zL2KyaKA+Im85uTHq3kJrgWC253OCS2EuBftAtrbLvVE7x5Ss9W 4aobMFCpAoKT4aNjDi3NjLkodw5oPL4yQntgbh60r7sTqBbEtVdOkjPK78tg+QTNxWPq q9Ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:feedback-id:mime-version:user-agent :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature; bh=SFxfwh/SNUbiBrbrBM7+VkdJkhyFe9+nbAS9qevE8ys=; b=NMQo1qA3PiWZ0frU6TXdbIQinOKnoxdh6tpfYD4BPeAfGWarr2Gh5JFfA3/dEJLIMq jdrvF+AD67zuNH0TtxxOB7Ct4Y4Ulk9x4hUnPZhvzjheH8VEhMJrUdOGmBbaxh/1ul8N QPUmAdZloRmlNfz9wh1A+VOm/NaRbjBEyv3ZwGM7xlwejThsZpkqy0PnjSnbFmCVg1Pp kv6+5gfpRGjnjfY/rlrXzwW27YB6MyMge2V4s2BFMn52qkfzU81704IiFOIp8+B30JeE PqWCf1tRPLe1TnMBKPuNs0We22H7tJCvK0V+wQKmxUl4wz4MnU3qOcRdR6XZb0RfeSkV MScg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=hLqARxqM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v5si5571140plg.318.2019.01.31.14.40.56; Thu, 31 Jan 2019 14:41:11 -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=@amazonses.com header.s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug header.b=hLqARxqM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727827AbfAaU5C (ORCPT + 99 others); Thu, 31 Jan 2019 15:57:02 -0500 Received: from a9-54.smtp-out.amazonses.com ([54.240.9.54]:34520 "EHLO a9-54.smtp-out.amazonses.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727077AbfAaU5C (ORCPT ); Thu, 31 Jan 2019 15:57:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=ug7nbtf4gccmlpwj322ax3p6ow6yfsug; d=amazonses.com; t=1548968221; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References:MIME-Version:Content-Type:Feedback-ID; bh=dn2omShFf6Xl/TI/yPpPBfhfVyM/8Yd9LQa5Ur1JErE=; b=hLqARxqMr9+W+Ok+DIFrw9CPp+3zlJfVJa/aN5zpPnPUiEYJ9cx2U2tdkScPQyjA blWFeKeMdTgA+ZRttarhxygb5Em/0phqnV6ourGkyjN0ZWPrJFKXTIhLihD0i9qtcra f8rPa6gSVs+oLdbrsB3JonOZujQVmmFDp85YA7GY= Date: Thu, 31 Jan 2019 20:57:01 +0000 From: Christopher Lameter X-X-Sender: cl@nuc-kabylake To: Thomas Garnier cc: kernel-hardening@lists.openwall.com, kristen@linux.intel.com, Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org, Dennis Zhou , Tejun Heo , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Andrew Morton , Andi Kleen , Thomas Garnier , "Kirill A. Shutemov" , Michal Hocko , Mike Rapoport , Stephen Rothwell , Cao jin , Brijesh Singh , Masahiro Yamada , Joerg Roedel , Peter Zijlstra , Kees Cook , Mathieu Desnoyers , linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org Subject: Re: [PATCH v6 14/27] x86/percpu: Adapt percpu for PIE support In-Reply-To: <20190131192533.34130-15-thgarnie@chromium.org> Message-ID: <01000168a5b35a86-b79bfe67-191e-43bc-a5c7-0e74eac06195-000000@email.amazonses.com> References: <20190131192533.34130-1-thgarnie@chromium.org> <20190131192533.34130-15-thgarnie@chromium.org> User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-SES-Outgoing: 2019.01.31-54.240.9.54 Feedback-ID: 1.us-east-1.fQZZZ0Xtj2+TD7V5apTT/NrT6QKuPgzCT/IC7XYgDKI=:AmazonSES Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. > 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.