From patchwork Fri Sep 28 14:08:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 10620045 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECC09913 for ; Fri, 28 Sep 2018 14:09:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCBF12AF18 for ; Fri, 28 Sep 2018 14:09:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0E302B4BD; Fri, 28 Sep 2018 14:09:25 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 58BC22AF18 for ; Fri, 28 Sep 2018 14:09:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728062AbeI1UdV (ORCPT ); Fri, 28 Sep 2018 16:33:21 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:38012 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727361AbeI1UdV (ORCPT ); Fri, 28 Sep 2018 16:33:21 -0400 Received: by mail-pg1-f195.google.com with SMTP id r77-v6so4577059pgr.5 for ; Fri, 28 Sep 2018 07:09:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=W4oT8/sMgtEq2xm5+6dbJ9THnUdqukOQrnCVRJknLJ0=; b=jfJo69MbAJkNac2vGKQivljU1r7kR1LMF5SBLOavXc/GUIwSqp1zEU8Bi1VonXSP1O 7hJvEOEY5hieBGPaZzlLnyIDnJgnMVlV2XUlc/z1MQiky8OjPnhWcUJKSbXrpC6JEPk2 SNaUcS1IY6blWVKAvPIk4EiBbdMkO1xk+XJKtXUNRAJAU4+gsRNqloR1B2cW8//ZeYOz 5IJqPWGgPcTeBJHXAZkCIWGahqOSkHK+ySgn5ACjpK5Vo2sSbeJ8hmYADrLPRtX9vsio ojWgi5Hvv73J35Go+65z4q5Bw0fkVNSPhfG4i69p82Uv5F/7F9DQJ9UbAQc6gEsP9MD8 dVzA== 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; bh=W4oT8/sMgtEq2xm5+6dbJ9THnUdqukOQrnCVRJknLJ0=; b=jCpwj/W2DUIb69eya2X3Wby6Vjlv9oVG4L88fAPzGPRC6W1AXdSrZb/tzr/Mweq8Ck /CEk4KY+x9g1dDerl2tDGo6HaFTMrqIySgvBjUQ7ao71lel5Q/CmzMiw3WS4t8lNShs/ tvyg33D1BA9R8KNuGbuJ06If58VnApvegG4xL0xpOdDQ5Z6MYQEafR7tGWikf/y56QmM yvU1G4zd6dq5FzYsQDgGZQkxQNt7SMrkoj6pBqmpV5f42SEJ5g3L0oyXVY2ej4FdPTaP qLLjnpbOS1RwwpJAeMeOxLStxt9HGYWFWSAMcK17am/SMyiBJskZ1PK9OEl1qGXwkafk bz6Q== X-Gm-Message-State: ABuFfojwUEzAVnNJEZITLgQclg5TCp/1uZMqOr7SrTGWMBxJ+1SPSgjD DRTcoEaIpPzu8U3tPsdL+00= X-Google-Smtp-Source: ACcGV61cy9A4/zY3PE9x7sPI2l9dySVFFk7TXe/juDnWZ1Ydon5/YrFPvFfrvMt1sn+jIyR9DFfuHw== X-Received: by 2002:a65:580d:: with SMTP id g13-v6mr8724474pgr.370.1538143762673; Fri, 28 Sep 2018 07:09:22 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id d129-v6sm6956977pga.69.2018.09.28.07.09.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 28 Sep 2018 07:09:22 -0700 (PDT) From: Wei Yang To: pbonzini@redhat.com, xiaoguangrong@tencent.com Cc: x86@kernel.org, kvm@vger.kernel.org, Wei Yang Subject: [PATCH] KVM: x86: move definition PT_MAX_HUGEPAGE_LEVEL and KVM_NR_PAGE_SIZES together Date: Fri, 28 Sep 2018 22:08:50 +0800 Message-Id: <20180928140850.42684-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.15.1 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, there are two definitions related to huge page, but a little bit far from each other and seems loosely connected: * KVM_NR_PAGE_SIZES defines the number of different size a page could map * PT_MAX_HUGEPAGE_LEVEL means the maximum level of huge page The number of different size a page could map equals the maximum level of huge page, which is implied by current definition. While current implementation may not be kind to readers and further developers: * KVM_NR_PAGE_SIZES looks like a stand alone definition at first sight * in case we need to support more level, two places need to change This patch tries to make these two definition more close, so that reader and developer would feel more comfortable to manipulate. Signed-off-by: Wei Yang --- arch/x86/include/asm/kvm_host.h | 10 +++++++++- arch/x86/kvm/mmu.h | 5 ----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 036dede47274..7422842caa9d 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -102,7 +102,15 @@ #define UNMAPPED_GVA (~(gpa_t)0) /* KVM Hugepage definitions for x86 */ -#define KVM_NR_PAGE_SIZES 3 +enum { + PT_PAGE_TABLE_LEVEL = 1, + PT_DIRECTORY_LEVEL = 2, + PT_PDPE_LEVEL = 3, + /* set max level to the biggest one */ + PT_MAX_HUGEPAGE_LEVEL = PT_PDPE_LEVEL, +}; +#define KVM_NR_PAGE_SIZES (PT_MAX_HUGEPAGE_LEVEL - \ + PT_PAGE_TABLE_LEVEL + 1) #define KVM_HPAGE_GFN_SHIFT(x) (((x) - 1) * 9) #define KVM_HPAGE_GFN_SIZE(x) (1UL << KVM_HPAGE_GFN_SHIFT(x)) #define KVM_HPAGE_GFN_MASK(x) (~(KVM_HPAGE_GFN_SIZE(x) - 1)) diff --git a/arch/x86/kvm/mmu.h b/arch/x86/kvm/mmu.h index 1fab69c0b2f3..99d549905311 100644 --- a/arch/x86/kvm/mmu.h +++ b/arch/x86/kvm/mmu.h @@ -43,11 +43,6 @@ #define PT32_ROOT_LEVEL 2 #define PT32E_ROOT_LEVEL 3 -#define PT_PDPE_LEVEL 3 -#define PT_DIRECTORY_LEVEL 2 -#define PT_PAGE_TABLE_LEVEL 1 -#define PT_MAX_HUGEPAGE_LEVEL (PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES - 1) - static inline u64 rsvd_bits(int s, int e) { if (e < s)