From patchwork Tue Feb 14 19:42:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Garnier X-Patchwork-Id: 9572649 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 406CC60573 for ; Tue, 14 Feb 2017 19:45:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3D1D428391 for ; Tue, 14 Feb 2017 19:45:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 312C3283A6; Tue, 14 Feb 2017 19:45:38 +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 93E1728391 for ; Tue, 14 Feb 2017 19:45:37 +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 1cdj0L-00023j-N0; Tue, 14 Feb 2017 19:43:13 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cdj0K-00022g-HM for xen-devel@lists.xenproject.org; Tue, 14 Feb 2017 19:43:12 +0000 Received: from [85.158.139.211] by server-5.bemta-5.messagelabs.com id 0C/7B-02139-FCD53A85; Tue, 14 Feb 2017 19:43:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrGIsWRWlGSWpSXmKPExsVyMfSWse652MU RBtv/GVt83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBl/9v9kLvjMW3H/+UG2BsZ53F2MXBxCAjMZ Jea2t7CBOCwCr1gkeq5dYAdxJAT6WSW+b5gKlOEEcmIkHu3+zg5hV0i8a7wHFhcSUJLYumEpM 8So/4wS/Z1bwRJsAloSexrmM4EkRATm8Ei83LKGGSTBLPCHUWLGTvMuRg4OYQFzidN99SBhFg FVicmv/zCC2LwCFhLXe/azQiwzlrjdf5oVpJxTwFJiy9tAiL0WEv/ffWKdwCiwgJFhFaNGcWp RWWqRrpGxXlJRZnpGSW5iZo6uoYGpXm5qcXFiempOYlKxXnJ+7iZGYGjVMzAw7mDc0e53iFGS g0lJlLciaHGEEF9SfkplRmJxRnxRaU5q8SFGGQ4OJQlephignGBRanpqRVpmDjDIYdISHDxKI ryRIGne4oLE3OLMdIjUKUZjjp6u0y+ZOPbsuvySSYglLz8vVUqc1xakVACkNKM0D24QLPouMc pKCfMyMjAwCPEUpBblZpagyr9iFOdgVBLmzQeZwpOZVwK37xXQKUxAp7DGLQQ5pSQRISXVwNi 56dqXGYnrVrYsf/L2Vgxf5YdaQdEdXUZWZ1c8FLUyNoqOMt6/6mBGwKO597WX+kg2uxxL7dE/ Lu9w8b2G+vLZr9YuUcy01P4Z0BJaJ78+oXz9y7779Vt+zJy5pkDzZbrlzSt3s2ekN14y8C+re mOc3D3zj5Gloed6nd6XYk6fdm3tXsS33UGJpTgj0VCLuag4EQAeqoj1uQIAAA== X-Env-Sender: thgarnie@google.com X-Msg-Ref: server-6.tower-206.messagelabs.com!1487101389!84706626!1 X-Originating-IP: [209.85.218.51] 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 52726 invoked from network); 14 Feb 2017 19:43:10 -0000 Received: from mail-oi0-f51.google.com (HELO mail-oi0-f51.google.com) (209.85.218.51) by server-6.tower-206.messagelabs.com with AES128-GCM-SHA256 encrypted SMTP; 14 Feb 2017 19:43:10 -0000 Received: by mail-oi0-f51.google.com with SMTP id u143so76230608oif.3 for ; Tue, 14 Feb 2017 11:43:10 -0800 (PST) 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=iitYwezpjUyKVmLZ7WNApIXSeCIdeGxFdEcLZjsh3tM=; b=FcN7wVg/2c8Ia2vGBx+J/t2x6g/UvK4bSKSXXz2fgQuWtIAGv7Uqfd3Jvhe55TlflG csZx2u2VNIqHK15IkTPKrQTX4p0CtZWJGD9WvyfS6Bn+mVSzNKWpqqw91VXhyqGcN2R8 mzrNlxrAtj/dWOgoGTr+QIdbobZhPNpuTPIb9ox2mSWahQ1uuz42Jpr9S/x3IS/T3oGC Kxwhvts3s8on2NycypenSOWlwdTd7wF8K57TKYR3duKj21I/b+jUIvRIqhMmzAq+jU++ Aqe2+smViYMpDr/uWwYujmpYcYMgRyJv54GaMnDjo1YkwHwgxt+/FSJzJNgvS8feQZk1 GP2g== 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=iitYwezpjUyKVmLZ7WNApIXSeCIdeGxFdEcLZjsh3tM=; b=jvZ/oXKXh+Vhj0B42ggI3gCv3WJyPv415XUCn/dWLhtwzDrAPk/NB1vP7bYznrs9WM o3JwbDzQyfhDgHjfoLvFOmqmZdAXCU39SJWd9PV1SjtAyD6o4aTYptLU0yBKlSw4lFpm MSXNTJn+kfZWQ7jzGEDeNy2HM2f9JhZrEBrKqBAVstGSUoiMdeSijSw7YDls1al2UwvG 4lgDq73upgrahCnr6i3wTTXXn4hiseC8OxiZZAHTpSSJm7X9aLym3WbfxUvJ8GgM9Qqg 7bWLYPb1BJKNqY3ZbUeBm/cpTkc6O6KH4B0SKIkbJJZwWlUBUhXlYRJhI5+BCHfst8MY 0DqA== X-Gm-Message-State: AMke39mLdtQmyuK9gIAnrxgjjKjsJ35wblyLpFUPDRuXkVQIHOZD5ncQxv6gVc1sO3T9WJrO X-Received: by 10.84.176.137 with SMTP id v9mr4000927plb.59.1487101389206; Tue, 14 Feb 2017 11:43:09 -0800 (PST) Received: from skynet.sea.corp.google.com ([100.100.206.185]) by smtp.gmail.com with ESMTPSA id r78sm2804161pfl.63.2017.02.14.11.43.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 14 Feb 2017 11:43:08 -0800 (PST) From: Thomas Garnier To: Thomas Gleixner , Ingo Molnar , "H . Peter Anvin" , Andrey Ryabinin , Alexander Potapenko , Dmitry Vyukov , Thomas Garnier , Kees Cook , Andy Lutomirski , Borislav Petkov , Paul Gortmaker , Andy Lutomirski , "Rafael J . Wysocki" , Len Brown , Pavel Machek , Jiri Kosina , Matt Fleming , Ard Biesheuvel , Boris Ostrovsky , Juergen Gross , Rusty Russell , Peter Zijlstra , Christian Borntraeger , "Luis R . Rodriguez" , He Chen , Brian Gerst , Stanislaw Gruszka , Arnd Bergmann , Adam Buchbinder , Dave Hansen , Vitaly Kuznetsov , Josh Poimboeuf , Tim Chen , Rik van Riel , Andi Kleen , Jiri Olsa , Michael Ellerman , Joerg Roedel , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= Date: Tue, 14 Feb 2017 11:42:59 -0800 Message-Id: <20170214194259.75960-4-thgarnie@google.com> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog In-Reply-To: <20170214194259.75960-1-thgarnie@google.com> References: <20170214194259.75960-1-thgarnie@google.com> Cc: linux-efi@vger.kernel.org, kvm@vger.kernel.org, linux-pm@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, lguest@lists.ozlabs.org, kernel-hardening@lists.openwall.com, xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH v3 4/4] KVM: VMX: Simplify segment_base 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 The KVM segment_base function is confusing. This patch replaces integers with appropriate flags, simplify constructs and add comments. Signed-off-by: Thomas Garnier --- Based on next-20170213 --- arch/x86/kvm/vmx.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c index 99167f20bc34..edb8326108dd 100644 --- a/arch/x86/kvm/vmx.c +++ b/arch/x86/kvm/vmx.c @@ -2062,25 +2062,35 @@ static unsigned long segment_base(u16 selector) struct desc_struct *d; unsigned long table_base; unsigned long v; + u32 high32; - if (!(selector & ~3)) + if (!(selector & ~SEGMENT_RPL_MASK)) return 0; - table_base = get_current_gdt_rw_vaddr(); - - if (selector & 4) { /* from ldt */ + /* LDT selector */ + if ((selector & SEGMENT_TI_MASK) == SEGMENT_LDT) { u16 ldt_selector = kvm_read_ldt(); - if (!(ldt_selector & ~3)) + if (!(ldt_selector & ~SEGMENT_RPL_MASK)) return 0; table_base = segment_base(ldt_selector); + } else { + table_base = get_current_gdt_rw_vaddr(); } - d = (struct desc_struct *)(table_base + (selector & ~7)); + + d = (struct desc_struct *)table_base + (selector >> 3); v = get_desc_base(d); #ifdef CONFIG_X86_64 - if (d->s == 0 && (d->type == 2 || d->type == 9 || d->type == 11)) - v |= ((unsigned long)((struct ldttss_desc64 *)d)->base3) << 32; + /* + * Extend the virtual address if we have a system descriptor entry for + * LDT or TSS (available or busy). + */ + if (d->s == 0 && (d->type == DESC_LDT || d->type == DESC_TSS || + d->type == 11/*Busy TSS */)) { + high32 = ((struct ldttss_desc64 *)d)->base3; + v |= (u64)high32 << 32; + } #endif return v; }