From patchwork Wed Mar 2 17:10:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8483931 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2149C9F314 for ; Wed, 2 Mar 2016 17:11:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4E1CC2022A for ; Wed, 2 Mar 2016 17:11:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 127F12038F for ; Wed, 2 Mar 2016 17:11:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754789AbcCBRLR (ORCPT ); Wed, 2 Mar 2016 12:11:17 -0500 Received: from mail-pf0-f169.google.com ([209.85.192.169]:35667 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754515AbcCBRLO (ORCPT ); Wed, 2 Mar 2016 12:11:14 -0500 Received: by mail-pf0-f169.google.com with SMTP id w128so92689930pfb.2 for ; Wed, 02 Mar 2016 09:11:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FCxWA31SLnE5Zy0bEqM3RuM8Z5s8n7kNV0bsMH7irjE=; b=Ji5Fxn7UfIaD799jaUu49xj9lwd/hTozzc6fIdvA+YQI2TcymbWJD4LC1Cjn8MBnyl UDvQqpKuORZveEFn2jxpoueIZC5AZoEzRYrZVkWA06olP5C7BQJxuSO1Lq40fsDqklIr bgZ4G7N88th/z+wIHBgv5l7fajBPq+O6ejd+h9IunfzVGaOmH+JRe1rSV7UWA4ifW4Nr sa991T0Vdy0qFGm22MbDDRVEaFC/IKxNqnhOv7unWzuAAB71192XoZgMmSp0rbRvtWfi /VbHHWa8uQyUyoxgDa15J1YBkYZ0pt/+h9504GbZ+MZqTuo3HFn6Yc/8vt5swJ71qF0S 6OfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FCxWA31SLnE5Zy0bEqM3RuM8Z5s8n7kNV0bsMH7irjE=; b=JmO+PqFP3RMlNwyYsRPwauyEjApFstcFbK15qFIPb1m8CJRLjzN1AVHTPMAGLw6XvX /lCPH+EfaO6ozMfvrlZWF2LyVk8ZInjfNRcslu8S9JnAhRh3GyIK8HR8r0Xvp/566lgk mIBv4Nfj5OHsrvnXjwu9/XrdnQmezfSk6ptH4vCdjMRnLYUIFKcVlhQ6MI9XDh3ui0pF GgligOG6l/VVN6acKSaxBntKuF4Evj8zSGo6s+bWAH/rqh5XDHGZVp6JxXq1ImZBzh9z xmJo7lKcW3IJW6uFEh7IY0TZZ0zO1U3IBXUk4q1jr3fZT/Fc7ZrQyG7wOq0L8JNVcLD6 GSCw== X-Gm-Message-State: AD7BkJK5GXq8OHBx2MdWdd+QsbW+EeT2+pkV4xHWGkF6cx2/Bu5ydAWXwTgSZqZaUd2vaH4s X-Received: by 10.98.13.216 with SMTP id 85mr39735540pfn.143.1456938666681; Wed, 02 Mar 2016 09:11:06 -0800 (PST) Received: from localhost ([2620:0:1009:3:10b2:1b3a:febc:1b15]) by smtp.gmail.com with ESMTPSA id fk10sm54343417pab.33.2016.03.02.09.11.05 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Wed, 02 Mar 2016 09:11:05 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, jan.kiszka@siemens.com, drjones@redhat.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests v3 4/6] x86: vmx: Named constant: EPT_LEVEL_SHIFT Date: Wed, 2 Mar 2016 09:10:55 -0800 Message-Id: <1456938657-20850-5-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456938657-20850-1-git-send-email-pfeiner@google.com> References: <1456860622-31251-1-git-send-email-pfeiner@google.com> <1456938657-20850-1-git-send-email-pfeiner@google.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Peter Feiner --- x86/vmx.c | 17 ++++++----------- x86/vmx.h | 1 + 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/x86/vmx.c b/x86/vmx.c index 9811a28..140ad86 100644 --- a/x86/vmx.c +++ b/x86/vmx.c @@ -233,7 +233,7 @@ void install_ept_entry(unsigned long *pml4, unsigned offset; for (level = EPT_PAGE_LEVEL; level > pte_level; --level) { - offset = (guest_addr >> ((level-1) * EPT_PGDIR_WIDTH + 12)) + offset = (guest_addr >> EPT_LEVEL_SHIFT(level)) & EPT_PGDIR_MASK; if (!(pt[offset] & (EPT_PRESENT))) { unsigned long *new_pt = pt_page; @@ -248,8 +248,7 @@ void install_ept_entry(unsigned long *pml4, pt[offset] &= ~EPT_LARGE_PAGE; pt = phys_to_virt(pt[offset] & EPT_ADDR_MASK); } - offset = ((unsigned long)guest_addr >> ((level-1) * - EPT_PGDIR_WIDTH + 12)) & EPT_PGDIR_MASK; + offset = (guest_addr >> EPT_LEVEL_SHIFT(level)) & EPT_PGDIR_MASK; pt[offset] = pte; } @@ -325,8 +324,7 @@ unsigned long get_ept_pte(unsigned long *pml4, if (level < 1 || level > 3) return -1; for (l = EPT_PAGE_LEVEL; ; --l) { - offset = (guest_addr >> (((l-1) * EPT_PGDIR_WIDTH) + 12)) - & EPT_PGDIR_MASK; + offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK; pte = pt[offset]; if (!(pte & (EPT_PRESENT))) return 0; @@ -336,8 +334,7 @@ unsigned long get_ept_pte(unsigned long *pml4, return pte; pt = (unsigned long *)(pte & EPT_ADDR_MASK); } - offset = (guest_addr >> (((l-1) * EPT_PGDIR_WIDTH) + 12)) - & EPT_PGDIR_MASK; + offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK; pte = pt[offset]; return pte; } @@ -372,16 +369,14 @@ int set_ept_pte(unsigned long *pml4, unsigned long guest_addr, if (level < 1 || level > 3) return -1; for (l = EPT_PAGE_LEVEL; ; --l) { - offset = (guest_addr >> (((l-1) * EPT_PGDIR_WIDTH) + 12)) - & EPT_PGDIR_MASK; + offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK; if (l == level) break; if (!(pt[offset] & (EPT_PRESENT))) return -1; pt = (unsigned long *)(pt[offset] & EPT_ADDR_MASK); } - offset = (guest_addr >> (((l-1) * EPT_PGDIR_WIDTH) + 12)) - & EPT_PGDIR_MASK; + offset = (guest_addr >> EPT_LEVEL_SHIFT(l)) & EPT_PGDIR_MASK; pt[offset] = pte_val; return 0; } diff --git a/x86/vmx.h b/x86/vmx.h index 459dd13..d3a852e 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -467,6 +467,7 @@ enum Ctrl1 { #define EPT_PAGE_LEVEL 4 #define EPT_PGDIR_WIDTH 9 #define EPT_PGDIR_MASK 511 +#define EPT_LEVEL_SHIFT(level) (((level)-1) * EPT_PGDIR_WIDTH + 12) #define EPT_ADDR_MASK GENMASK_ULL(51, 12) #define PAGE_MASK (~(PAGE_SIZE-1)) #define PAGE_MASK_2M (~(PAGE_SIZE_2M-1))