From patchwork Thu Feb 16 16:48:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Zijlstra X-Patchwork-Id: 9577725 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 D5C5060209 for ; Thu, 16 Feb 2017 16:50:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C74872862B for ; Thu, 16 Feb 2017 16:50:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BBD8428647; Thu, 16 Feb 2017 16:50:33 +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 3F5552862B for ; Thu, 16 Feb 2017 16:50:33 +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 1cePEP-0000pl-Db; Thu, 16 Feb 2017 16:48:33 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cePEN-0000pc-H6 for xen-devel@lists.xenproject.org; Thu, 16 Feb 2017 16:48:31 +0000 Received: from [85.158.143.35] by server-7.bemta-6.messagelabs.com id E3/C0-26824-ED7D5A85; Thu, 16 Feb 2017 16:48:30 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFIsWRWlGSWpSXmKPExsVy9qV1m+6960s jDCYeFLT4vmUykwOjx+EPV1gCGKNYM/OS8isSWDNmfrnEUrBCuGL3hA6WBsZtAl2MXBwsAsfY JKatnM0E4ggJ3GSUOD+1mxHCaWSU+DHrO3MXIydQmapEx8vJQFUcHGwC2hLXOnxAwiICKhIdb 3+wgdQzC6xglVh37jkjSEJYIFHi7e2tLCA2r4CzxMK9b1lBbCGBComvb+4yQ8QFJU7OfAJWwy ygJXHj30uw+cwC0hLL/3GAhDkFnCSOdR0AGykqoCbR9XwO+wRG/llIumch6Z6F0L2AkXkVo0Z xalFZapGuoZleUlFmekZJbmJmjq6hgZlebmpxcWJ6ak5iUrFecn7uJkZgGDIAwQ7G+xsDDjFK cjApifL+6F8aIcSXlJ9SmZFYnBFfVJqTWnyIUYaDQ0mClwEY1kKCRanpqRVpmTnAiIBJS3DwK InwXroGlOYtLkjMLc5Mh0idYlSUEuddD5IQAElklObBtcGi8BKjrJQwLyPQIUI8BalFuZklqP KvGMU5GJWEeTeATOHJzCuBm/4KaDET0OLOCLDFJYkIKakGxqNW0at3lYR9a1SQmHJ65em1aUx NL5nsGernSMQsq/n7UWmb0/rFeQnHjrwNe/h1UpTw7RSbL+mM7/c27f94xNH6Pq964v2zj7Tn rOcMXjmrW8mSOeuxmkD0x0UrZ1d8e3hsa2C6GveR+fncEWkzBP7otz36oKjxqzc8dq3FxltLN 60tfCIYwa7EUpyRaKjFXFScCABmO+EsvQIAAA== X-Env-Sender: peterz@infradead.org X-Msg-Ref: server-6.tower-21.messagelabs.com!1487263709!35085252!1 X-Originating-IP: [205.233.59.134] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogMjA1LjIzMy41OS4xMzQgPT4gMTcxNDMx\n X-StarScan-Received: X-StarScan-Version: 9.2.3; banners=-,-,- X-VirusChecked: Checked Received: (qmail 28998 invoked from network); 16 Feb 2017 16:48:30 -0000 Received: from merlin.infradead.org (HELO merlin.infradead.org) (205.233.59.134) by server-6.tower-21.messagelabs.com with AES256-GCM-SHA384 encrypted SMTP; 16 Feb 2017 16:48:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=sG/Ym+1vGfi9FQlST+40HjXLl24bt2dEV5P+4WcQSyM=; b=IJekljhYU+rgIh2SShb/p1s5F wQwOVGIkdlQVU0rtwgl7/Vd+/DFWA8vcIVLW1n4hDfZareWQI7+Ujk5DkVruWHXlKhTVmf8cYw3ZN Qi6QgFGLfDlKp03G8BbIho1dgOAObkMGywMO+sFfUT6yXnqWrMzYA9dNWsqTfikR4+Qo+Vfz8NkLT 3MxSbLg2W/r2upBrIcNyocxx9HaP7pI27UV3dSs0N0FH5l5YEawGyBV18iqvrT5bJOhvFd8pNxDo9 DqDNS5YhbcHdfW+qAb+6+0QCC3OSIw8ENxl4k/mlzVFHSuKJPWM5C69NDv2FSEBAVou9lwJV5kGoy /rBvCTktQ==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=twins.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.87 #1 (Red Hat Linux)) id 1cePE5-0006M8-T1; Thu, 16 Feb 2017 16:48:14 +0000 Received: by twins.programming.kicks-ass.net (Postfix, from userid 1000) id 3B2ED1256AA9C; Thu, 16 Feb 2017 17:48:15 +0100 (CET) Date: Thu, 16 Feb 2017 17:48:15 +0100 From: Peter Zijlstra To: Waiman Long Message-ID: <20170216164815.GD6515@twins.programming.kicks-ass.net> References: <1487194670-6319-1-git-send-email-longman@redhat.com> <1487194670-6319-3-git-send-email-longman@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1487194670-6319-3-git-send-email-longman@redhat.com> 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 , andrew.cooper3@citrix.com, "H. Peter Anvin" , xen-devel@lists.xenproject.org, Alok Kataria , Thomas Gleixner Subject: Re: [Xen-devel] [PATCH v4 2/2] x86/kvm: Provide optimized version of vcpu_is_preempted() for x86-64 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 Wed, Feb 15, 2017 at 04:37:50PM -0500, Waiman Long wrote: > +/* > + * Hand-optimize version for x86-64 to avoid 8 64-bit register saving and > + * restoring to/from the stack. It is assumed that the preempted value > + * is at an offset of 16 from the beginning of the kvm_steal_time structure > + * which is verified by the BUILD_BUG_ON() macro below. > + */ > +#define PREEMPTED_OFFSET 16 As per Andrew's suggestion, the 'right' way is something like so. --- asm-offsets_64.c | 11 +++++++++++ kvm.c | 14 ++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) --- a/arch/x86/kernel/asm-offsets_64.c +++ b/arch/x86/kernel/asm-offsets_64.c @@ -13,6 +13,10 @@ static char syscalls_ia32[] = { #include }; +#ifdef CONFIG_KVM_GUEST +#include +#endif + int main(void) { #ifdef CONFIG_PARAVIRT @@ -22,6 +26,13 @@ int main(void) BLANK(); #endif +#ifdef CONFIG_KVM_GUEST +#ifdef CONFIG_PARAVIRT_SPINLOCKS + OFFSET(KVM_STEAL_TIME_preempted, kvm_steal_time, preempted); + BLANK(); +#endif +#endif + #define ENTRY(entry) OFFSET(pt_regs_ ## entry, pt_regs, entry) ENTRY(bx); ENTRY(cx); --- a/arch/x86/kernel/kvm.c +++ b/arch/x86/kernel/kvm.c @@ -600,22 +600,21 @@ PV_CALLEE_SAVE_REGS_THUNK(__kvm_vcpu_is_ #else +#include + extern bool __raw_callee_save___kvm_vcpu_is_preempted(long); /* * Hand-optimize version for x86-64 to avoid 8 64-bit register saving and - * restoring to/from the stack. It is assumed that the preempted value - * is at an offset of 16 from the beginning of the kvm_steal_time structure - * which is verified by the BUILD_BUG_ON() macro below. + * restoring to/from the stack. */ -#define PREEMPTED_OFFSET 16 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:" "movq __per_cpu_offset(,%rdi,8), %rax;" -"cmpb $0, " __stringify(PREEMPTED_OFFSET) "+steal_time(%rax);" +"cmpb $0, " __stringify(KVM_STEAL_TIME_preempted) "+steal_time(%rax);" "setne %al;" "ret;" ".popsection"); @@ -627,11 +626,6 @@ asm( */ void __init kvm_spinlock_init(void) { -#ifdef CONFIG_X86_64 - BUILD_BUG_ON((offsetof(struct kvm_steal_time, preempted) - != PREEMPTED_OFFSET) || (sizeof(steal_time.preempted) != 1)); -#endif - if (!kvm_para_available()) return; /* Does host kernel support KVM_FEATURE_PV_UNHALT? */