From patchwork Tue Jul 18 22:33:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9850057 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6A00760392 for ; Tue, 18 Jul 2017 22:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55942285CD for ; Tue, 18 Jul 2017 22:37:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49F08285E7; Tue, 18 Jul 2017 22:37:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D3D15285CD for ; Tue, 18 Jul 2017 22:37:06 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXb4Q-0000RP-4e; Tue, 18 Jul 2017 22:34:22 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dXb4P-0000Qr-Pw for xen-devel@lists.xenproject.org; Tue, 18 Jul 2017 22:34:21 +0000 Received: from [193.109.254.147] by server-7.bemta-6.messagelabs.com id A2/DF-03557-DEC8E695; Tue, 18 Jul 2017 22:34:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsVyMfTAat03PXm RBv+/MFt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBkTDxxlKzggXHF+0iWmBsajAl2MXBxCAjMZ JS5u2cMI4rAIvGKR+PV0EQuIIyHQzyrRv+YFkMMJ5MRJbLy6hhnCrpJ4/qwPzBYSUJLYumEpM 8Sof4wS53dfZgVJsAloSexpmM8EkhARmM0hsbjrDNhYAYGPbBI3thwGa2EWaGGSePJvG1AZB4 ewgIVE959ckG4WAVWJx1N2sIPYvAKWEpe3vWQHKZEQMJb4+0UfxOQUsJJYfp8H4ghLid7eBpY JjIILGBlWMWoUpxaVpRbpGhnrJRVlpmeU5CZm5ugaGpjp5aYWFyemp+YkJhXrJefnbmIEBh0D EOxg/DM/8BCjJAeTkijvVuW8SCG+pPyUyozE4oz4otKc1OJDjDIcHEoSvL7dQDnBotT01Iq0z Bxg+MOkJTh4lER4fUDSvMUFibnFmekQqVOMlhxXrqz7wsQx5cB2IPlqwv9vTEIsefl5qVLivC IgDQIgDRmleXDjYDF6iVFWSpiXEehAIZ6C1KLczBJU+VeM4hyMSsK8/SBTeDLzSuC2vgI6iAn oIGHfHJCDShIRUlINjAmfOmYX1dxNkfQVX3Vj1nmGxJN1tVHGm76ybn3btuGsv8hLaSb5fPEr 96VSp6u6CIRfZs3JuXlKnDE3o19h1qtYfvOehV+Dj17uejTt59niNe45az8EKT0LOKi+XOJvQ RQ/P9PGBdvOqP206dgSaucry3YnrPLfRJ7ke9XW1k7Fs3LjXH5VKbEUZyQaajEXFScCAM0O5s /MAgAA X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-14.tower-27.messagelabs.com!1500417258!95343493!1 X-Originating-IP: [209.85.192.171] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.25; banners=-,-,- X-VirusChecked: Checked Received: (qmail 12275 invoked from network); 18 Jul 2017 22:34:19 -0000 Received: from mail-pf0-f171.google.com (HELO mail-pf0-f171.google.com) (209.85.192.171) by server-14.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 18 Jul 2017 22:34:19 -0000 Received: by mail-pf0-f171.google.com with SMTP id q85so17854696pfq.1 for ; Tue, 18 Jul 2017 15:34:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gwOoWDToyUJfGjVKFh3ZWtmQSRCdD8kihWU6M/TXDt0=; b=bPYBhjEmqDN9TMJMWarX6Wsmv4d/eiFG463xFuFap6Tr7VzzAiiARZitLjSn3hotVH xrnFegJ56yxdEh1uEnozoIRgUrcQSi+3dVe7hTl/dD7gRK+hvxGEEGwhdPXsljFFIydp es0Hh3uaiYEXJ6blOnd0SipmfgEAAxWYxpwZhYOwbht3jJAyRBVdAbMW3hkGnYHibTyV 5MKQVaAU+3RhLBIvX7QE0nEHDAB90N9HNWmzS8Lboxmc8/OhleXppfhRXPUlouwn/Wqj L92pYskxroUdm3YS0ijJT2S2V0xelT2mNzOqcCCqVE3y6thJ/AczA/4aIEhbCKdHyKK9 9oRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gwOoWDToyUJfGjVKFh3ZWtmQSRCdD8kihWU6M/TXDt0=; b=FVcB7JfvPla2rb2zuBJzk+9GOiJW9g5qlraRmnUNu8JQcE2ppM9yH7uIGkRhCTT6tn Co7tuljHPyCCPjc6vTJV5skmxVJMaxlK2GQVCRq2t3ZvpEotswAQqaHwujovJD9R4RqZ 3ZXzXGFH2kieYS6ogzI/ZLvV1NWLtYu6W7HuYrngNv0kkDq7p40cR6N3SYX+xFBpR+Dz 7z9UrnEilBnRh94k7Sz6TQE5yL49E4UcbLlvu03DqZO7d3umcLet224m9nxH7chKKf8J zqZ2ut5HNjEMMTzpm3XR+BMGOZ9KeKYxpk0IIKgIeUagz8IB5XW1jMReGUfC1m6yIKxz ZdZw== X-Gm-Message-State: AIVw1121ZVC7OlGJa/G4fEaCd+MefHDaRIAHWy1jHdKT+ds5evU4ukKf W7WLBVd/T+5ib7Sz X-Received: by 10.84.224.207 with SMTP id k15mr4266385pln.108.1500417258199; Tue, 18 Jul 2017 15:34:18 -0700 (PDT) Received: from skynet.sea.corp.google.com ([100.100.206.164]) by smtp.gmail.com with ESMTPSA id b6sm6444242pgn.67.2017.07.18.15.34.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 15:34:17 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Thomas Garnier , Arnd Bergmann , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Andy Lutomirski , Borislav Petkov , "Kirill A . Shutemov" , Brian Gerst , Borislav Petkov , Christian Borntraeger , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Tejun Heo , Christoph Lameter , Kees Cook , Paul Gortmaker , Chris Metcalf , "Paul E . McKenney" , Andrew Morton , Christopher Li , Dou Liyang , Masahiro Yamada , Daniel Borkmann , Markus Trippelsdorf , Peter Foley , Steven Rostedt , Tim Chen , Ard Biesheuvel , Catalin Marinas , Matthew Wilcox , Michal Hocko , Rob Landley , Jiri Kosina , "H . J . Lu" , Paul Bolle , Baoquan He , Daniel Micay Date: Tue, 18 Jul 2017 15:33:17 -0700 Message-Id: <20170718223333.110371-7-thgarnie@google.com> X-Mailer: git-send-email 2.13.2.932.g7449e964c-goog In-Reply-To: <20170718223333.110371-1-thgarnie@google.com> References: <20170718223333.110371-1-thgarnie@google.com> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [RFC 06/22] kvm: Adapt assembly for PIE support X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Change the assembly code to use only relative references of symbols for the kernel to be PIE compatible. The new __ASM_GET_PTR_PRE macro is used to get the address of a symbol on both 32 and 64-bit with PIE support. Position Independent Executable (PIE) support will allow to extended the KASLR randomization range below the -2G memory limit. Signed-off-by: Thomas Garnier --- arch/x86/include/asm/kvm_host.h | 6 ++++-- arch/x86/kernel/kvm.c | 6 ++++-- arch/x86/kvm/svm.c | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 87ac4fba6d8e..3041201a3aeb 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1352,9 +1352,11 @@ asmlinkage void kvm_spurious_fault(void); ".pushsection .fixup, \"ax\" \n" \ "667: \n\t" \ cleanup_insn "\n\t" \ - "cmpb $0, kvm_rebooting \n\t" \ + "cmpb $0, kvm_rebooting" __ASM_SEL(,(%%rip)) " \n\t" \ "jne 668b \n\t" \ - __ASM_SIZE(push) " $666b \n\t" \ + __ASM_SIZE(push) "%%" _ASM_AX " \n\t" \ + __ASM_GET_PTR_PRE(666b) "%%" _ASM_AX "\n\t" \ + "xchg %%" _ASM_AX ", (%%" _ASM_SP ") \n\t" \ "call kvm_spurious_fault \n\t" \ ".popsection \n\t" \ _ASM_EXTABLE(666b, 667b) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 71c17a5be983..53b8ad162589 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -618,8 +618,10 @@ asm( ".global __raw_callee_save___kvm_vcpu_is_preempted;" ".type __raw_callee_save___kvm_vcpu_is_preempted, @function;" "__raw_callee_save___kvm_vcpu_is_preempted:" -"movq __per_cpu_offset(,%rdi,8), %rax;" -"cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax);" +"leaq __per_cpu_offset(%rip), %rax;" +"movq (%rax,%rdi,8), %rax;" +"addq " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rip), %rax;" +"cmpb $0, (%rax);" "setne %al;" "ret;" ".popsection"); diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c index 4d8141e533c3..8b718c6d6729 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -554,12 +554,12 @@ static u32 svm_msrpm_offset(u32 msr) static inline void clgi(void) { - asm volatile (__ex(SVM_CLGI)); + asm volatile (__ex(SVM_CLGI) : :); } static inline void stgi(void) { - asm volatile (__ex(SVM_STGI)); + asm volatile (__ex(SVM_STGI) : :); } static inline void invlpga(unsigned long addr, u32 asid)