From patchwork Thu Aug 10 17:25:58 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9894355 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 C17CA60236 for ; Thu, 10 Aug 2017 17:29:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A896628A39 for ; Thu, 10 Aug 2017 17:29:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9CC5D28A93; Thu, 10 Aug 2017 17:29:29 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_MED, 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 3B19728A39 for ; Thu, 10 Aug 2017 17:29:29 +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 1dfrEW-0007bh-Rz; Thu, 10 Aug 2017 17:26:56 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dfrEV-0007a3-QA for xen-devel@lists.xenproject.org; Thu, 10 Aug 2017 17:26:55 +0000 Received: from [85.158.139.211] by server-3.bemta-5.messagelabs.com id 20/BE-02033-F579C895; Thu, 10 Aug 2017 17:26:55 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrBIsWRWlGSWpSXmKPExsXiVRusrxs3vSf S4PllfovvWyYzOTB6HP5whSWAMYo1My8pvyKBNePBtVfMBQeFK06cPMzcwHhMoIuRi0NIYDqj RPuUi+wgDovAKxaJ7tNnmEAcCYF+VonNB7aydDFyAjlxEj+mLGWFsCskFrbvZgKxhQSUJLZuW MoMMeofo8S7tZ/ZQBJsAloSexrmg00SEVgqKHGy9RojiMMs0MIk8eTfNqAMB4ewgLXE9i1cIA 0sAqoSD/e/ANvAK2AhceP1RjaIbSYST1onMYLYnAKWEtOWzWSG2GwhMfXXSqYJjAILGBlWMWo UpxaVpRbpGlnoJRVlpmeU5CZm5ugaGpjq5aYWFyemp+YkJhXrJefnbmIEhlc9AwPjDsa+VX6H GCU5mJREeYs/dUcK8SXlp1RmJBZnxBeV5qQWH2KU4eBQkuDln9YTKSRYlJqeWpGWmQMMdJi0B AePkgjv1qlAad7igsTc4sx0iNQpRmOOSQe2f2HieDXh/zcmIZa8/LxUKXHefSCTBEBKM0rz4A bBIvASo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWFeV5ApPJl5JXD7XgGdwgR0SoRvJ8gpJYk IKakGRueGzkK56Oqgg+yHNKaeSc9g3vRamU9GtKhHcM3lefoXzGL6bmyf1G52hKeE07fZRDrQ fFHdq0eHL0Uq5jJfTH6qW/3Aqc75R9SxwkrRQywFKarvYv65Se7skE5/d7tqjR/nNMaUU4ELl r48HxfTlHo/2az92xplraepnnd79EUPCW7u4FRTYinOSDTUYi4qTgQALwgSorsCAAA= X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-5.tower-206.messagelabs.com!1502386013!105121586!1 X-Originating-IP: [74.125.83.47] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 19994 invoked from network); 10 Aug 2017 17:26:53 -0000 Received: from mail-pg0-f47.google.com (HELO mail-pg0-f47.google.com) (74.125.83.47) by server-5.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 10 Aug 2017 17:26:53 -0000 Received: by mail-pg0-f47.google.com with SMTP id l64so5396949pge.5 for ; Thu, 10 Aug 2017 10:26:53 -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=+feb5JWcMEDr4skHQpGjd9tMdVNIwzVPuTT/v8JtT3E=; b=CCotmWLRvEbtwZEa9Qd+XP+mR9+1rrVC6CmrsAGHxvAVD7DwYPgsgoWb4ZL/C6mXT7 GcXL6Hgrs1mAtlPQMlCXpEhsU23m5ijXKCVYM6uL/CPifWKHtEQLEvGZ5FZs3Z4aDpfE 1eRFynvkGF/+diSnOYIFFyHbqaptUH4tJ/bxukJZmMS56wvdTLaui7Jv7JSbqA+nO7d6 ckdyLJwH30OyX0xPZzyq3utQUDG7Ov7uvpTcPBKex4TvIcyeZ3fGRaiyXszEFSORF3S+ zMfdbg76qb33QAX7LjQzyoc+1jwLqCLT+PNO598uOcEdRXlLTcFP4qVGM76xyFxIo1jM sI6A== 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=+feb5JWcMEDr4skHQpGjd9tMdVNIwzVPuTT/v8JtT3E=; b=LrEuKwCVQh5/cjtTBBL0dNgLEwq9BKM+YiGK2+loE/RNza8Xvnst3Zjg9/8tt+AmDA pSpuB1IRr3Km+ljXtW822kE9oWybnN+4YM1Xd3pHN/j3NdPMglzZanu9xnw0VQyzQDU5 Y6Ht632FovyKVRz1EMcHYzx/UJcbDJSA0tpWXs6lkdDTeKyYTbVeA7PJ2uoBAsY7FEBg 77Tn24YjnQuxeflCQ699BuDKwohgb+HoIl/ExvNm/f1H15b+PqU5zvbaE2En8Hkwepoz D0sTa8p3NJ7k1L49yyLRtB3gTFdsK72oCiRLvq8igRljb8kPe6HWGOojczNx9II7pT07 uyrA== X-Gm-Message-State: AHYfb5gdxF0Nptjh+pN3ulRbpL5O9RwApxl++2b83NjZAEaPEPbvJICm yDLka7X5UkJvHgLL X-Received: by 10.98.141.1 with SMTP id z1mr13357749pfd.260.1502386012160; Thu, 10 Aug 2017 10:26:52 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id p77sm11894925pfi.153.2017.08.10.10.26.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 10 Aug 2017 10:26:51 -0700 (PDT) From: Thomas Garnier To: Herbert Xu , "David S . Miller" , Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Peter Zijlstra , Josh Poimboeuf , Arnd Bergmann , Thomas Garnier , Matthias Kaehlcke , Boris Ostrovsky , Juergen Gross , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Tom Lendacky , Andy Lutomirski , Borislav Petkov , Brian Gerst , "Kirill A . Shutemov" , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Tejun Heo , Christoph Lameter , Paul Gortmaker , Chris Metcalf , Andrew Morton , "Paul E . McKenney" , Nicolas Pitre , Christopher Li , "Rafael J . Wysocki" , Lukas Wunner , Mika Westerberg , Dou Liyang , Daniel Borkmann , Alexei Starovoitov , Masahiro Yamada , Markus Trippelsdorf , Steven Rostedt , Kees Cook , Rik van Riel , David Howells , Waiman Long , Kyle Huey , Peter Foley , Tim Chen , Catalin Marinas , Ard Biesheuvel , Michal Hocko , Matthew Wilcox , "H . J . Lu" , Paul Bolle , Rob Landley , Baoquan He , Daniel Micay Date: Thu, 10 Aug 2017 10:25:58 -0700 Message-Id: <20170810172615.51965-7-thgarnie@google.com> X-Mailer: git-send-email 2.14.0.434.g98096fd7a8-goog In-Reply-To: <20170810172615.51965-1-thgarnie@google.com> References: <20170810172615.51965-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 v2 06/23] 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 7cbaab523f22..276e288da25e 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 d04e30e3c0ff..cb83745185f2 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -620,8 +620,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 4d4743361f1e..6e611f9f6163 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)