From patchwork Tue Mar 1 19:30:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8469651 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 716559F2F0 for ; Tue, 1 Mar 2016 19:31:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A00652034E for ; Tue, 1 Mar 2016 19:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id ACD0E202E5 for ; Tue, 1 Mar 2016 19:31:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752069AbcCATbD (ORCPT ); Tue, 1 Mar 2016 14:31:03 -0500 Received: from mail-pa0-f49.google.com ([209.85.220.49]:34428 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752058AbcCATbB (ORCPT ); Tue, 1 Mar 2016 14:31:01 -0500 Received: by mail-pa0-f49.google.com with SMTP id fy10so117227641pac.1 for ; Tue, 01 Mar 2016 11:31:01 -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=r7BZNGozaLVbk8ZqqQE7Kod+Dp6vvmLXUwMAU6gZclA=; b=nAPWBq4OwcPzvaJNwWHqiKbxmbQ8FyrxpogvPifkf1AyVxYOEJhzui0fZ780w5Fc0X duAUchCI78iEi8e9ksmRKqUhry/uIZlJHHOetnT/Uxj+tJhPmub2ucNPYV87WGl7WP0q 0d1CtkqGB8+UCR2RfK1XKG5woSYipjtqSSw5jNHO++CbBseJWqF17qf8LannVD/2ywJv GFw+am15vMWqmZlyOCC2fquRS1TFf4uPmTYKyvFfwmfynXehXgp5sLIUZQONgM8IvRQ6 6SOwJiD5iOVD6QHXm/pqLXGueUXjhkQO8ZEGZ8mZ1GYMkpLQSSYulb1Mpu+t5zV8ywwK I0eQ== 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=r7BZNGozaLVbk8ZqqQE7Kod+Dp6vvmLXUwMAU6gZclA=; b=dDdFaLmYMyXMlAPQQ0gzcLNHhBRHuk4z7MjZtHTYQ3t9dqPnA0+IXkGo4KjJN7qLeH I6S4pWmyVsZnjEbpT+1jZeajK0+x6QfbLOkdd2YvTOWWhPGLXKPlMEAVup9fty4IlIvR brMLcqHUsvM0xPvb9nGB4yZ4TX1K+G0qKoJI9QgBTk97PU4tqk5UtQ+oR5GbLs4Aonk8 mNIcME2vHOwjTQVkZ3Zjpo7Huu9hpFfDXrgQ0aVeTVootb/+dEDlJN13HpCfrAGJdT1t E83DRjC4/iKdeq0dnYKxVeHhUXmcL8CW4WTDv9Q6/jCz5XfKW4WCtNwgwy/5Fwgxvdaz zFpA== X-Gm-Message-State: AD7BkJJeCf9wpow+CYHgRK5hx9FlHHpODWueqIY+TyhECN4zjm0iMXr4JRNRxGmSbhQHYCRz X-Received: by 10.66.62.169 with SMTP id z9mr32268701par.139.1456860660703; Tue, 01 Mar 2016 11:31:00 -0800 (PST) Received: from localhost ([2620:0:1009:3:b1e9:1d95:1ce5:e70c]) by smtp.gmail.com with ESMTPSA id a25sm6434509pfj.40.2016.03.01.11.30.59 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 11:31:00 -0800 (PST) From: Peter Feiner To: kvm@vger.kernel.org, jan.kiszka@siemens.com, pbonzini@redhat.com Cc: pfeiner@google.com Subject: [kvm-unit-tests 3/5] x86: vmx: Named constant: EPT_LEVEL_SHIFT Date: Tue, 1 Mar 2016 11:30:20 -0800 Message-Id: <1456860622-31251-4-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456860622-31251-1-git-send-email-pfeiner@google.com> References: <1456860622-31251-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 c2a2121..0b646fa 100644 --- a/x86/vmx.h +++ b/x86/vmx.h @@ -466,6 +466,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 0xffffffffff000ul #define PAGE_MASK (~(PAGE_SIZE-1)) #define PAGE_MASK_2M (~(PAGE_SIZE_2M-1))