From patchwork Wed Oct 4 21:19:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9985521 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 30AAA60586 for ; Wed, 4 Oct 2017 21:23:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20B2E28C2C for ; Wed, 4 Oct 2017 21:23:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 13F0A28C2F; Wed, 4 Oct 2017 21:23:03 +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 A82F728C2C for ; Wed, 4 Oct 2017 21:23:02 +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 1dzr6a-0003DT-Ar; Wed, 04 Oct 2017 21:21:24 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dzr6Z-0003Bv-JL for xen-devel@lists.xenproject.org; Wed, 04 Oct 2017 21:21:23 +0000 Received: from [193.109.254.147] by server-6.bemta-6.messagelabs.com id C6/5E-03435-3D055D95; Wed, 04 Oct 2017 21:21:23 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrFIsWRWlGSWpSXmKPExsVyMfTAZt0LAVc jDc7dYLT4vmUykwOjx+EPV1gCGKNYM/OS8isSWDPWzjvJXHBQuOLk5SssDYzHBLoYuTiEBGYy Ssy5f5MNxGEReMUisf3XcjBHQqCfVeLXtEbmLkZOICdLovFQEyOEnSbxau5fFgi7SuLp8/dgc SEBJYmtG5YyQ4z9yyixYel/VpAEm4CWxJ6G+UwgCRGBWSISt173gK1gFjjDJHG87yRYlbCAtc Sy1U/BxrIIqErMnX8dKM7BwStgKfHjZibENhOJh0eugZVzAoWPnHjDDLHZQqL1zH2mCYyCCxg ZVjFqFKcWlaUW6RqZ6SUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn525iBIYdAxDsYDyz IPAQoyQHk5Io7ybfq5FCfEn5KZUZicUZ8UWlOanFhxhlODiUJHgj/IFygkWp6akVaZk5wAiAS Utw8CiJ8IaBpHmLCxJzizPTIVKnGC05Lty59IeJ48CeW0Cy4+bdP0xCLHn5ealS4rymIA0CIA 0ZpXlw42BReolRVkqYlxHoQCGegtSi3MwSVPlXjOIcjErCvNogU3gy80rgtr4COogJ6KA5TVd ADipJREhJNTAyHkuY9Czw+6pgu821iwuDkvb2KggJ5W3TSzEI6LPYbDSj0CXkf/EfbtfE7hjV ee4X8z95ZP6L0Xrgfn/Pei+Z9rTL4Uob/uwqDFjLwjnHZ2/Pvfl3KmxX5vvsOnlG4PWC+0ZTZ v1waz7Y5HK82/C0yCm7jD9XM09purn+6N/tXfTDusP+YqcSS3FGoqEWc1FxIgAtqGEQzQIAAA == X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-2.tower-27.messagelabs.com!1507152078!60411623!1 X-Originating-IP: [209.85.192.179] 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 13283 invoked from network); 4 Oct 2017 21:21:19 -0000 Received: from mail-pf0-f179.google.com (HELO mail-pf0-f179.google.com) (209.85.192.179) by server-2.tower-27.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 4 Oct 2017 21:21:19 -0000 Received: by mail-pf0-f179.google.com with SMTP id g65so6884618pfe.13 for ; Wed, 04 Oct 2017 14:21: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=sCfGKUIsl+jKNw8fWjd2pq3Fe0ytJweHGH66ceBPppA=; b=Yai6YPSVX3G/dpg6fphefW3ow+eU7UmwAG5oKMJLJxRtVUs+IIvGqzRKXK+tn7lawd dw0k520bFbI4wwPBJ+SV60iKIkv/CrQdrz53M5/nhDWWYIkLoWdIpeH2MUkbxmhaenuN sLPZ0tg4rXNDmnqkIcBfuEQTK3l8Qm46H0CXk6LBv/CETG8asQQyFBEIcsSH4BGkDZYu ZkFz+SGpNn4VvI2gD7HDE5j+riIgoy2IXGNxN/lobIFw+vY9h+XR7qhVbEnYgGMct/OJ rDiB6EniZVodU67lQomO+VyfnkZ2YmkdEyMLVvfgi0hWJSWtW4CiRWjP4Q9Door3Pkxs wRLg== 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=sCfGKUIsl+jKNw8fWjd2pq3Fe0ytJweHGH66ceBPppA=; b=Yes/ZbIruaKnwaPjKydnQ99jCYgwc7q2acoLY5ubJ8EIGgd3NzPlEvqbPfs6wbMHc4 Tlpx9k2R4V+8qu5VAs/t98aBVy8k0aoS04O1f4/BqfPz5+HtohlYoDwMvPJYOhwhQjII nuMs3YG0c3ZWEuVTnH09Yzqf8WWquDarjXxlJxyZc5/9QJFvwCF39IzZ77zJr8nmGuPN LbDadyY8cGg9OzG85C4IQ24O97P/a6/mg1xRQbXvXxhde1AB/7rGGP/o6sgxHpN+EBkQ ySsb3sBrt4jfc5dGAn+nwor6GNeE68b0DJ+kIujl20DkuHAKCblB6hYJmdGoFkokmJ8G rCZw== X-Gm-Message-State: AHPjjUiOhRtdABAD9hXKkpsqwvPWFQfswZawX/3Yl7b3xFpwURG1KrtJ r6ZBDR+KUFv0jn2aRCThJGj5mA== X-Google-Smtp-Source: AOwi7QCcdFW8itArwMSABhO0agWpP9MppnnCi0D/iZezdxptqzlnA78lS7M99CvxHWXASyY7cAsfmg== X-Received: by 10.84.174.129 with SMTP id r1mr20632665plb.390.1507152077892; Wed, 04 Oct 2017 14:21:17 -0700 (PDT) Received: from skynet.sea.corp.google.com ([172.31.92.33]) by smtp.gmail.com with ESMTPSA id s68sm30204019pfd.72.2017.10.04.14.21.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Oct 2017 14:21:16 -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 , Kees Cook , 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 , Alexey Dobriyan , Andrew Morton , Paul Gortmaker , Chris Metcalf , "Paul E . McKenney" , Nicolas Pitre , Borislav Petkov , "Luis R . Rodriguez" , Greg Kroah-Hartman , Christopher Li , Steven Rostedt , Jason Baron , Dou Liyang , "Rafael J . Wysocki" , Mika Westerberg , 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 , Andrey Ryabinin , Jonathan Corbet , Matthew Wilcox , Michal Hocko , Peter Foley , Paul Bolle , Jiri Kosina , Rob Landley , "H . J . Lu" , Baoquan He , =?UTF-8?q?Jan=20H=20=2E=20Sch=C3=B6nherr?= , Daniel Micay Date: Wed, 4 Oct 2017 14:19:54 -0700 Message-Id: <20171004212003.28296-19-thgarnie@google.com> X-Mailer: git-send-email 2.14.2.920.gcf0c67979c-goog In-Reply-To: <20171004212003.28296-1-thgarnie@google.com> References: <20171004212003.28296-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] [RFC v3 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 aa60a08b65b1..07176bfc188b 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 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)