From patchwork Tue Feb 14 16:03:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 9572167 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 962906045F for ; Tue, 14 Feb 2017 16:05:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 81D29283F9 for ; Tue, 14 Feb 2017 16:05:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7647628427; Tue, 14 Feb 2017 16:05:31 +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_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 49998283F9 for ; Tue, 14 Feb 2017 16:05: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 1cdfZb-0003q0-SX; Tue, 14 Feb 2017 16:03:23 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdfZa-0003pf-JE for xen-devel@lists.xenproject.org; Tue, 14 Feb 2017 16:03:22 +0000 Received: from [85.158.139.211] by server-7.bemta-5.messagelabs.com id A2/D7-02154-94A23A85; Tue, 14 Feb 2017 16:03:21 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrKIsWRWlGSWpSXmKPExsXiaHS5VddTa3G EwcNmdovvWyYzOTB6HP5whSWAMYo1My8pvyKBNePF1CmsBT0SFZtuNTM3MM4S7mLk4mAROMEm 0XdlDxuIIyRwm1GipXEycxcjJ5DTyCix4WcwiM0ioCpx6PEeli5GDg42AW2Jax0+IGERARWJj rc/wHqZBXpZJXYvvc8GkhAWiJFY27OdFcTmFXCW2HmmkRViwWIWiZ9r21ggEoISJ2c+AbOZBb Qkbvx7yQSygFlAWmL5Pw6QMKeAncSH9dfBSkQF1CS6ns9hn8DIPwtJ9ywk3bMQuhcwMq9iVC9 OLSpLLdI10UsqykzPKMlNzMzRNTQw1ctNLS5OTE/NSUwq1kvOz93ECAxCBiDYwXirz/kQoyQH k5Ior53Q4gghvqT8lMqMxOKM+KLSnNTiQ4wyHBxKEryZmkA5waLU9NSKtMwcYDzApCU4eJREe PtA0rzFBYm5xZnpEKlTjLoci3afeckkxJKXn5cqJc5rDVIkAFKUUZoHNwIWm5cYZaWEeRmBjh LiKUgtys0sQZV/xSjOwagkzJsNMoUnM68EbtMroCOYgI5gjVsIckRJIkJKqoFRzt/pccrEMOV 6Jlkho71aNZEqLbemHjT93r/+UvY87bbueMv3WT8bzlR35s5fPd2C76OSBnN/1Nn8VFvhGTp7 UgR2LOldvt3RlW/S9scbb591KLgWp/tx++PFedlJUz5fZPC/uu86V9DKivPzrxuu1xa8dvjDO U2Tcxd2bd/KGnv9623BqJ4XSizFGYmGWsxFxYkA+GweX8gCAAA= X-Env-Sender: peterz@infradead.org X-Msg-Ref: server-14.tower-206.messagelabs.com!1487088199!46044326!1 X-Originating-IP: [65.50.211.133] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 55181 invoked from network); 14 Feb 2017 16:03:20 -0000 Received: from bombadil.infradead.org (HELO bombadil.infradead.org) (65.50.211.133) by server-14.tower-206.messagelabs.com with AES256-GCM-SHA384 encrypted SMTP; 14 Feb 2017 16:03:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bTixdVGIIedrBtt9oHio7vIGIbW7J4TqlB/kJIWGzQM=; b=npxC9L3vLxJwiwU6kQOvPM78v 2M3eHEisGnaVrJ6qNcPhBKCA/ipUvzGeauDUzgBg8GF6OA5K2Q9ChLzMAvTVn70L2HDd4BVyp/s69 tvgbqscRE2oFakbpWmLgPhj5bNXUmZqYDUVKC+/1sUB/GtzwJxd2RvxPp7q6GyPntpgzuvLCOyk1d Sa0Rx9HqPVPcEuqNIvAI/Ha15PiSp12BatpKyMX/X3yC+iXZS5ek/q7X7ur62vkiEiFLQzwyN/bnR h0VQxXIKF16WU4f4cPIXC/dO9LMhaWVgfo5mUWbyc4SR2rkK7oyknd/pgh8mTDG4lAndhgbWleTRs oy3LRhr3w==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=twins.programming.kicks-ass.net) by bombadil.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1cdfZK-0000Kv-Bm; Tue, 14 Feb 2017 16:03:06 +0000 Received: by twins.programming.kicks-ass.net (Postfix, from userid 1000) id 36E4F1256AA9C; Tue, 14 Feb 2017 17:03:06 +0100 (CET) Date: Tue, 14 Feb 2017 17:03:06 +0100 From: Peter Zijlstra To: Waiman Long Message-ID: <20170214160306.GP6500@twins.programming.kicks-ass.net> References: <1c949ed0-1b88-ae6e-4e6c-426502bfab5f@redhat.com> <14854496-0baa-1bf6-c819-f3d7fae13c2c@redhat.com> <20170213104716.GM6515@twins.programming.kicks-ass.net> <20170213105343.GJ6536@twins.programming.kicks-ass.net> <3dc50409-60dd-ad47-f971-448191e66038@redhat.com> <6f69b112-7ae4-bf8f-b767-29a68fd48632@redhat.com> <20170213215220.GN25813@worktop.programming.kicks-ass.net> <933ba8c6-4ebe-63e2-3c3a-2e5afef9269a@redhat.com> <20170214093946.GM6500@twins.programming.kicks-ass.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23.1 (2014-03-12) Cc: linux-arch@vger.kernel.org, Juergen Gross , Jeremy Fitzhardinge , x86@kernel.org, kvm@vger.kernel.org, Radim =?utf-8?B?S3LEjW3DocWZ?= , Boris Ostrovsky , Pan Xinhui , Paolo Bonzini , Rusty Russell , linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, Chris Wright , Ingo Molnar , "H. Peter Anvin" , xen-devel@lists.xenproject.org, Alok Kataria , Thomas Gleixner Subject: Re: [Xen-devel] [PATCH v2] x86/paravirt: Don't make vcpu_is_preempted() a callee-save function 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: , Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP On Tue, Feb 14, 2017 at 09:46:17AM -0500, Waiman Long wrote: > On 02/14/2017 04:39 AM, Peter Zijlstra wrote: > > On Mon, Feb 13, 2017 at 05:34:01PM -0500, Waiman Long wrote: > >> It is the address of &steal_time that will exceed the 32-bit limit. > > That seems extremely unlikely. That would mean we have more than 4G > > worth of per-cpu variables declared in the kernel. > > I have some doubt about if the compiler is able to properly use > RIP-relative addressing for this. Its not RIP relative, &steal_time lives in the .data..percpu section and is absolute in that. > Anyway, it seems like constraints > aren't allowed for asm() when not in the function context, at least for > the the compiler that I am using (4.8.5). So it is a moot point. Well kvm_steal_time is (host/guest) ABI anyway, so the offset is fixed and hard-coding it isn't a problem. $ readelf -s defconfig-build/vmlinux | grep steal_time 100843: 0000000000017ac0 64 OBJECT WEAK DEFAULT 35 steal_time $ objdump -dr defconfig-build/vmlinux | awk '/[<][^>]*[>]:/ { o=0 } /[<]__raw_callee_save___kvm_vcpu_is_preempted[>]:/ {o=1} { if (o) print $0 }' ffffffff810b4480 <__raw_callee_save___kvm_vcpu_is_preempted>: ffffffff810b4480: 55 push %rbp ffffffff810b4481: 48 89 e5 mov %rsp,%rbp ffffffff810b4484: 48 8b 04 fd 00 94 46 mov -0x7db96c00(,%rdi,8),%rax ffffffff810b448b: 82 ffffffff810b4488: R_X86_64_32S __per_cpu_offset ffffffff810b448c: 80 b8 d0 7a 01 00 00 cmpb $0x0,0x17ad0(%rax) ffffffff810b448e: R_X86_64_32S steal_time+0x10 ffffffff810b4493: 0f 95 c0 setne %al ffffffff810b4496: 5d pop %rbp ffffffff810b4497: c3 retq And as you'll note, the displacement is correct and 'small'. The below relies on the 'extra' cast in PVOP_CALL_ARG1() to extend the argument to 64bit on the call side of things. --- arch/x86/kernel/kvm.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c index 099fcba..2c854b8 100644 --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -589,6 +589,7 @@ static void kvm_wait(u8 *ptr, u8 val) local_irq_restore(flags); } +#ifdef CONFIG_X86_32 __visible bool __kvm_vcpu_is_preempted(int cpu) { struct kvm_steal_time *src = &per_cpu(steal_time, cpu); @@ -597,6 +598,26 @@ __visible bool __kvm_vcpu_is_preempted(int cpu) } PV_CALLEE_SAVE_REGS_THUNK(__kvm_vcpu_is_preempted); +#else + +extern bool __raw_callee_save___kvm_vcpu_is_preempted(int cpu); + +asm( +".pushsection .text;" +".global __raw_callee_save___kvm_vcpu_is_preempted;" +".type __raw_callee_save___kvm_vcpu_is_preempted, @function;" +"__raw_callee_save___kvm_vcpu_is_preempted:" +FRAME_BEGIN +"movq __per_cpu_offset(,%rdi,8), %rax;" +"cmpb $0, 16+steal_time(%rax);" +"setne %al;" +FRAME_END +"ret;" +".popsection" +); + +#endif + /* * Setup pv_lock_ops to exploit KVM_FEATURE_PV_UNHALT if present. */