From patchwork Tue Mar 1 22:34:52 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 8471111 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BFB92C0553 for ; Tue, 1 Mar 2016 22:35:26 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E1EE3202EC for ; Tue, 1 Mar 2016 22:35:25 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 091BE2034E for ; Tue, 1 Mar 2016 22:35:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751573AbcCAWfW (ORCPT ); Tue, 1 Mar 2016 17:35:22 -0500 Received: from mail-pf0-f175.google.com ([209.85.192.175]:33058 "EHLO mail-pf0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751888AbcCAWfV (ORCPT ); Tue, 1 Mar 2016 17:35:21 -0500 Received: by mail-pf0-f175.google.com with SMTP id 124so59085245pfg.0 for ; Tue, 01 Mar 2016 14:35:20 -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=ofLnaKQvg2yrZImF0KfalnQBDGB9tRfj7dpwSKMQ3Pw=; b=Mcc+y4EU5kBZYlkxKWijysBO/U+yn2/EKX826KrI+HKyPy1NEgM4F0SRXII4zQC8SO eySh86HTbs25Ja5SQy31bcB7569WrS+04TjLIAi5B0JwKjJKr13RPDBeO52IDIT1IBde 6LNUHt33DndzB0gDH+yqnVq79kbBD9bg5D+UySsq2OkeH39ffWKSsaNaWWae7NErwfl2 sbx1JQzvKi5Jf69yQeHSvZofjFgCmgVOZBRRRpxmnTMrQyIKgh7ikJazeFCedfZ9z8xi v/vxyYphzjDLm0evqsfKtF44KKWy7yeBAaldPke36GxPU1ZDwF8u/EMv5xd3b8BFfKrE H5Qg== 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=ofLnaKQvg2yrZImF0KfalnQBDGB9tRfj7dpwSKMQ3Pw=; b=IyPGqL+0M67QKgZwlFHJ+uevptCynKTrt2vm4Iy26ZUKaTvUwV8Ho71OG4uN7JnCeG j7YCaQ/xWt495O+8i3uerVozoMEc5OTAW7rW+Qr0Q+8ZtMpxr6a2MVXX8ykelbWJR43+ 8zSyaL7d5H+yIxhDb0TL7AMJZjNc7lDeLxT1t6mSK7qtW6W3SMTk9v1NEBTueW1MV2tG FoT09EXousZ4qHcsarHGEwx9DkmwFnaSlnW7gdKeiK58Phvq/knCH1+mp8ME97B2VkJa huTxCnR7Jbrr8+yKmrS7QUNdfnpZshwXLX+bsGbpa79cJxiEuYrOxNrIGWpQ1pfgyv+E igwA== X-Gm-Message-State: AD7BkJLrdHJQVUh1DD0BnsFr75pwPonFceAlNCYQ4FkKQieFw+PtNJcXopMixB4L8E0dxxpa X-Received: by 10.98.34.205 with SMTP id p74mr10509621pfj.93.1456871720292; Tue, 01 Mar 2016 14:35:20 -0800 (PST) Received: from localhost ([2620:0:1009:3:b1e9:1d95:1ce5:e70c]) by smtp.gmail.com with ESMTPSA id e79sm47811171pfb.76.2016.03.01.14.35.19 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 01 Mar 2016 14:35:19 -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 v2 4/6] x86: vmx: Named constant: EPT_LEVEL_SHIFT Date: Tue, 1 Mar 2016 14:34:52 -0800 Message-Id: <1456871694-23042-5-git-send-email-pfeiner@google.com> X-Mailer: git-send-email 2.7.0.rc3.207.g0ac5344 In-Reply-To: <1456871694-23042-1-git-send-email-pfeiner@google.com> References: <1456860622-31251-1-git-send-email-pfeiner@google.com> <1456871694-23042-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=ham 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 616ffc0..018051a 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(52, 11) #define PAGE_MASK (~(PAGE_SIZE-1)) #define PAGE_MASK_2M (~(PAGE_SIZE_2M-1))