From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967882AbeE2XIj (ORCPT ); Tue, 29 May 2018 19:08:39 -0400 Received: from mail-it0-f67.google.com ([209.85.214.67]:40620 "EHLO mail-it0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S935846AbeE2XIg (ORCPT ); Tue, 29 May 2018 19:08:36 -0400 X-Google-Smtp-Source: ADUXVKKQEXmZ6nbccvXE1f990udGICFw5EsD1HPSGS3FAJyApyp6NMQafGPul+yYHJPaF357XJzh65oXxUtQX1lseCY= MIME-Version: 1.0 References: <20180529221625.33541-1-thgarnie@google.com> <20180529221625.33541-15-thgarnie@google.com> <01000163ae145cac-5ac07b51-8f08-4da5-bb93-0238d59756d3-000000@email.amazonses.com> In-Reply-To: <01000163ae145cac-5ac07b51-8f08-4da5-bb93-0238d59756d3-000000@email.amazonses.com> From: Thomas Garnier Date: Tue, 29 May 2018 16:08:24 -0700 Message-ID: Subject: Re: [PATCH v4 14/27] x86/percpu: Adapt percpu for PIE support To: Christoph Lameter Cc: Kernel Hardening , Dave Hansen , Vitaly Kuznetsov , Tom Lendacky , Skip Mathieu Desnoyers , Skip Frederic Weisbecker , Nicholas Piggin , Kees Cook , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , "the arch/x86 maintainers" , Tejun Heo , Dennis Zhou , Boris Ostrovsky , Juergen Gross , Dominik Brodowski , Borislav Petkov , Josh Poimboeuf , Andy Lutomirski , Peter Zijlstra , "Kirill A. Shutemov" , Andrew Morton , Philippe Ombredanne , Greg KH , Alexey Dobriyan , Francis Deslauriers , Masahiro Yamada , Cao jin , Masami Hiramatsu , "Paul E . McKenney" , Nicolas Pitre , Randy Dunlap , LKML , xen-devel Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, May 29, 2018 at 3:46 PM Christopher Lameter wrote: > On Tue, 29 May 2018, Thomas Garnier wrote: > > Perpcu uses a clever design where the .percu ELF section has a virtual > > address of zero and the relocation code avoid relocating specific > > symbols. It makes the code simple and easily adaptable with or without > > SMP support. > > > > This design is incompatible with PIE because generated code always try to > > access the zero virtual address relative to the default mapping address. > We always access relative to the "segment register". > You can already change the segment register to relocate the per cpu > sections arbitrarily since all per cpu "addresses" are offsets relative to > the segment register. I am not sure what exactly you are trying to > accomplish here? When building with PIE, the compiler wants the code to be relocatable anywhere in the 64-bit VA space. Instead of taking the segment register as an immediate value, it takes it as VA that need to be relocated relative to where the kernel is mapped. The per-cpu section VA is zero to create the proper offset to the different variable. The kernel could be at the top of the 64-bit VA space. PIE will try to create the delta between any VA and zero and fail because segment register based operations do not have full 64-bit VA range. Does it make sense? For PIE only, this change will remove the per-cpu section VA of zero. Now the distance between the per-cpu symbol and the kernel base VA can fit in the generated instructions. > Maybe you need to explain it better? I will try do explain it better on the next patch set. -- Thomas