From patchwork Wed Oct 11 20:30:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 10000533 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 949606037F for ; Wed, 11 Oct 2017 20:33:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8917528B37 for ; Wed, 11 Oct 2017 20:33:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7CD0A28B6A; Wed, 11 Oct 2017 20:33:12 +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 EC63128B37 for ; Wed, 11 Oct 2017 20:33:11 +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 1e2NfE-0000ju-JZ; Wed, 11 Oct 2017 20:31:36 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1e2NfD-0000aH-LJ for xen-devel@lists.xenproject.org; Wed, 11 Oct 2017 20:31:35 +0000 Received: from [85.158.139.211] by server-17.bemta-5.messagelabs.com id A5/E9-22397-7AF7ED95; Wed, 11 Oct 2017 20:31:35 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsVyMfTARt1l9fc iDY5dkLf4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPmTz/JXnBUuOLEX54GxlMCXYxcHEICMxkl Jk74wtrFyMnBIvCKReL2pGyQhIRAP6vE6fPT2UASEgJZEpNP7mCEsNMk7nz5CBUvl/h4ZhULi C0koCSxdcNSZoip/xgl7jfcBmtgE9CS2NMwnwkkISJwQlhi04ffjCAOs8AZJonjfSfBdgsL2E r86LoAdYeqxKVVS5hBbF4BS4npazpYINZZSBw7dhjM5gSKf994iBlitYXEylnnWScwCi5gZFj FqFGcWlSWWqRraKKXVJSZnlGSm5iZo2toYKqXm1pcnJiempOYVKyXnJ+7iREYdAxAsIPx7GnP Q4ySHExKorwPY+5FCvEl5adUZiQWZ8QXleakFh9ilOHgUJLgTaoDygkWpaanVqRl5gDDHyYtw cGjJMLrBZLmLS5IzC3OTIdInWK05Lhw59IfJo4De24ByY6bd/8wCbHk5eelSonzvqsFahAAac gozYMbB4vRS4yyUsK8jEAHCvEUpBblZpagyr9iFOdgVBLmDQJZy5OZVwK39RXQQUxAB4mm3QE 5qCQRISXVwMij9kS9Snzept3qlcsWP7xQsaWrf4uvupBU7YxeZZ1lzksuLvssZh6oNcPr7KmU 6Pu/Vk06xR91XnXywcqw4JXpXgnpHvEer8N+XPQoq7qReP/Uv6cuzSFn7s65VM/RGLO5rqzNM vWEoLBX3MtLctLbnETKut8eZ32uxMD73ft8ZHjig6qVN5VYijMSDbWYi4oTAacTZg7MAgAA X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-8.tower-206.messagelabs.com!1507753893!106424579!1 X-Originating-IP: [209.85.192.177] 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 3491 invoked from network); 11 Oct 2017 20:31:34 -0000 Received: from mail-pf0-f177.google.com (HELO mail-pf0-f177.google.com) (209.85.192.177) by server-8.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 11 Oct 2017 20:31:34 -0000 Received: by mail-pf0-f177.google.com with SMTP id l188so1949530pfc.6 for ; Wed, 11 Oct 2017 13:31:34 -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=6JOt+36G4lnOwgcUNIawhxlOJXhYuUdLWAxdCXjckzg=; b=uoZuauwLcg2JI4orJV0IJwasOht/awASyTxG//tQ8Y5TeVMoMDZUwsrJ+CI4hdh16r 8kkAEyPP6cCJ/6FkqygCXgQysK3urj+TBYiqh8C95PlSsHd9hbCqMbsLcjhl4QtQKjlC 1NNYiWweCWWdpTYM/uzkjuSxCbOBSjmaQj3i24t1+8CH8AKxzBZR8kziRtH/OHZYZmOA PkNQgFdKZwTeeeg2RgH4m5NU5gty9xD6PyPi3ZWRLr/UBnXrZVi6xoszuaHNkOYBXMmG AmhO0TPs9kxhfTE5e5jdRjSYaqnXO7MGCbjGHOlD+ef0zP6ls0adDh4JMXYw2aUZrzNI ndjA== 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=6JOt+36G4lnOwgcUNIawhxlOJXhYuUdLWAxdCXjckzg=; b=A37ORAGaSc3zaDPw+wJNAQgtWg4kwNKzE0jaIAHOvcr54jt4JBaLTMX2F3RUeCJMDJ MbyfUnupMLVKzaShEtctGly+2Al4oAGrsizSCxwiVJ1OHmKGbcuY7pA/Co0zF1HIoNa4 Pft+d7hZh3Gm4X3O65kW55++QBj5ILZWRymWw8eiUBPMNTsZeLNG7cahsEZTIK6KaGNS 1SnSNWpnp9sys5NxRp7OvfBu+w8mKHVhW/IPuoNNK4qm2wrTzL26CF86SaCAgeD7i/T+ BnRVOeKJNnw2kJR/8gypRmQSgOerzF7MTwiBTvNXYEokfXOfDalKfuXJcpsXLnmM2/14 uC6A== X-Gm-Message-State: AMCzsaWwiwy5QMS5fH4mOv2v1nsWwGCCkOMtkyUPKF3Z/4KhNjmvWWo2 Zwv63ieG6UXIdNxY+fgZFFhIrg== X-Google-Smtp-Source: AOwi7QCA63qolilMW+Y7TDy4MpUrrlY8H5x09DS2tu73Fn/ul388DHiOizx+IbeIYCKP34oj03VDSg== X-Received: by 10.101.70.138 with SMTP id h10mr196488pgr.8.1507753892359; Wed, 11 Oct 2017 13:31:32 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id n12sm20691913pfb.149.2017.10.11.13.31.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 11 Oct 2017 13:31:31 -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 , Kees Cook , Andrey Ryabinin , Matthias Kaehlcke , Tom Lendacky , Andy Lutomirski , "Kirill A . Shutemov" , Borislav Petkov , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Juergen Gross , Chris Wright , Alok Kataria , Rusty Russell , Tejun Heo , Christoph Lameter , Boris Ostrovsky , Paul Gortmaker , Andrew Morton , Alexey Dobriyan , "Paul E . McKenney" , Nicolas Pitre , Borislav Petkov , "Luis R . Rodriguez" , Greg Kroah-Hartman , Christopher Li , Steven Rostedt , Jason Baron , Mika Westerberg , Dou Liyang , "Rafael J . Wysocki" , Lukas Wunner , Masahiro Yamada , Alexei Starovoitov , Daniel Borkmann , Markus Trippelsdorf , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , Joerg Roedel , Rik van Riel , David Howells , Ard Biesheuvel , Waiman Long , Kyle Huey , Jonathan Corbet , Michal Hocko , Peter Foley , Paul Bolle , Jiri Kosina , "H . J . Lu" , Rob Landley , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay Date: Wed, 11 Oct 2017 13:30:18 -0700 Message-Id: <20171011203027.11248-19-thgarnie@google.com> X-Mailer: git-send-email 2.15.0.rc0.271.g36b669edcc-goog In-Reply-To: <20171011203027.11248-1-thgarnie@google.com> References: <20171011203027.11248-1-thgarnie@google.com> Cc: linux-arch@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-sparse@vger.kernel.org, linux-crypto@vger.kernel.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v1 18/27] 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 9d7d856b2d89..14073fda75fb 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1342,9 +1342,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 8bb9594d0761..4464c3667831 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -627,8 +627,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 0e68f0b3cbf7..364536080438 100644 --- a/arch/x86/kvm/svm.c +++ b/arch/x86/kvm/svm.c @@ -568,12 +568,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)