Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6098221pxv; Thu, 29 Jul 2021 06:30:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/xkz0ywuIckdjY3L1kFLTAmfzTo9r7/NN/5kLua3uKVwBDJFS9IyCJyC2dOz0Vf2xWasH X-Received: by 2002:a6b:c812:: with SMTP id y18mr4030018iof.3.1627565404879; Thu, 29 Jul 2021 06:30:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627565404; cv=none; d=google.com; s=arc-20160816; b=q9c+AD6ZAJtPJG8w78q8gm2IkfSHOpsYcbJZkXRnm7NV4dOtB8T/A/5TqZM0GFH2aC gap/ihuaDZozn8xwXKZp7tevfNL2dRvn1udXf0ILsQMnQeAd0yjJEk9k0z9zfU0JO4NH 1wZKMJKo6bnOYkvZyLigTahG2mxgJWcfcbM15CKTpO9yy920F2kDcBEtG5eewTKtNkih SBhCViyfWvu0sFwtyGzA4Vu8lnPLWc4d3ldBzlyuNGtMLXwYzeH/xlzeyZU1Fb0gzBqZ lHLOOuE9OHyJFHEJl7uXMewxqVkEWud0ivakLIGLnDUbT6GU4+Y4RWJ1InQvu3OPmEG2 v9tQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=Cv7PfXmwJJr5mkYfUmsrSSKe76wdqOHk3bYX3NKK1Ak=; b=GBxy2ZScyaaSVvAtfSJMZECoCOhb8FFquyC7RdHbWqLWb78FthvseF8kmDpD2w3eV/ NOLUtkLL0i7J/jsQxdfkkJ8RYJOly4RkCgqiVOqDQ/xwbqckBWUj5gznRN7XN0KesJZ5 dqH65777uweCQqSV09KhET+LSOVZLng010czKrKQe3MPRAgCJu/t9KB359JMpA9xSvkX mMUWf0IhJcif1ehwN6pmcXDnvMnYVpiRNPnXffxhrmcx3RVYv/5h+7as2eb0/AVp+sWP hC4EynZbRl8xKrJAr53yjiVkFjsrleiaa0H+12d/f0HeZsEv7C85ukgsahCzHx4JUcnE Z5hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AbwsfISe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y11si3673052jat.64.2021.07.29.06.29.53; Thu, 29 Jul 2021 06:30:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AbwsfISe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237656AbhG2N2q (ORCPT + 99 others); Thu, 29 Jul 2021 09:28:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237599AbhG2N2j (ORCPT ); Thu, 29 Jul 2021 09:28:39 -0400 Received: from mail-qk1-x74a.google.com (mail-qk1-x74a.google.com [IPv6:2607:f8b0:4864:20::74a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45673C0613CF for ; Thu, 29 Jul 2021 06:28:35 -0700 (PDT) Received: by mail-qk1-x74a.google.com with SMTP id j12-20020a05620a146cb02903ad9c5e94baso3796094qkl.16 for ; Thu, 29 Jul 2021 06:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Cv7PfXmwJJr5mkYfUmsrSSKe76wdqOHk3bYX3NKK1Ak=; b=AbwsfISePdR+JcDYjzhjFaE1bsJCrdANuvRjTecRQQceHXv3IeTh0J7jJlARwdsQ8G lK2RNR40PdH2ybX+4B8/SG5a625FiCm/DG6T+1x0H/dzjUtP5pUIoKsaQjGt8zEfItZi PA2DJfQTPDIWY7IetC/uKiLRnyWOgkqH2qZXfcaBRUV/7fy/9vJazfZA57wTRE+X99Hs NLie91Ls49QGVPdQSkA8SAEtC+Bglx/wmSdONWh4h0p+VikY71TxLpKomLxhPbNKrqWS xWl4/oTTHN7Ikt7nqOsL9aqOKYUcBZl+aN86Yz90LGWUGeKx1Y9CVB4ZlhG1Ky5d+eEO 92kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Cv7PfXmwJJr5mkYfUmsrSSKe76wdqOHk3bYX3NKK1Ak=; b=VcLSVSmcFY4eI/ugO/axgfQRnZTA8buBYHAl4Avtgc4I1fcTgjOxZo2l8TcKB+m1cu LH5k7zguqnRHxaN9T9MP4bdOqo8ewtTwd6K5JMnnmLpOvcNWQ97raXazTuTnrFrUrD5e RKGFf7Gx68pBA0kpV10xSV2nL+2x3/vpseGOZEBItsPSUsN5IHyiUzsg2XKuQzFzhbUp GQ/rGfy9EeUVD+NrFHSgW5cDBEHvgV4yaSVVKvynuxpcS0AynCRelTOZWYmxEDjr65iA RZyo4DNqDNqagPVvR9Gg14JDL1j8i0wFq40K79DiI5KxLz1lU9ku+qbBXBMqR8MC6u70 DKIQ== X-Gm-Message-State: AOAM530pIg00cZkG99s5XR/TwrpkFl+apoUO+EQeJCPpWiu5xdAS00tW CwwuhQXsHzfJZRCMJQnQgvXgWx+5Dr6F X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:293a:bc89:7514:5218]) (user=qperret job=sendgmr) by 2002:a05:6214:84:: with SMTP id n4mr5338927qvr.4.1627565314337; Thu, 29 Jul 2021 06:28:34 -0700 (PDT) Date: Thu, 29 Jul 2021 14:28:02 +0100 In-Reply-To: <20210729132818.4091769-1-qperret@google.com> Message-Id: <20210729132818.4091769-6-qperret@google.com> Mime-Version: 1.0 References: <20210729132818.4091769-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 05/21] KVM: arm64: Expose page-table helpers From: Quentin Perret To: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, Quentin Perret Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The KVM pgtable API exposes the kvm_pgtable_walk() function to allow the definition of walkers outside of pgtable.c. However, it is not easy to implement any of those walkers without some of the low-level helpers. Move some of them to the header file to allow re-use from other places. Signed-off-by: Quentin Perret --- arch/arm64/include/asm/kvm_pgtable.h | 40 ++++++++++++++++++++++++++++ arch/arm64/kvm/hyp/pgtable.c | 39 --------------------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h index 082b9d65f40b..6938eac72c1f 100644 --- a/arch/arm64/include/asm/kvm_pgtable.h +++ b/arch/arm64/include/asm/kvm_pgtable.h @@ -25,6 +25,46 @@ static inline u64 kvm_get_parange(u64 mmfr0) typedef u64 kvm_pte_t; +#define KVM_PTE_VALID BIT(0) + +#define KVM_PTE_ADDR_MASK GENMASK(47, PAGE_SHIFT) +#define KVM_PTE_ADDR_51_48 GENMASK(15, 12) + +static inline bool kvm_pte_valid(kvm_pte_t pte) +{ + return pte & KVM_PTE_VALID; +} + +static inline u64 kvm_pte_to_phys(kvm_pte_t pte) +{ + u64 pa = pte & KVM_PTE_ADDR_MASK; + + if (PAGE_SHIFT == 16) + pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48; + + return pa; +} + +static inline u64 kvm_granule_shift(u32 level) +{ + /* Assumes KVM_PGTABLE_MAX_LEVELS is 4 */ + return ARM64_HW_PGTABLE_LEVEL_SHIFT(level); +} + +static inline u64 kvm_granule_size(u32 level) +{ + return BIT(kvm_granule_shift(level)); +} + +static inline bool kvm_level_supports_block_mapping(u32 level) +{ + /* + * Reject invalid block mappings and don't bother with 4TB mappings for + * 52-bit PAs. + */ + return !(level == 0 || (PAGE_SIZE != SZ_4K && level == 1)); +} + /** * struct kvm_pgtable_mm_ops - Memory management callbacks. * @zalloc_page: Allocate a single zeroed memory page. diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 78f36bd5df6c..49d768b92997 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -11,16 +11,12 @@ #include #include -#define KVM_PTE_VALID BIT(0) #define KVM_PTE_TYPE BIT(1) #define KVM_PTE_TYPE_BLOCK 0 #define KVM_PTE_TYPE_PAGE 1 #define KVM_PTE_TYPE_TABLE 1 -#define KVM_PTE_ADDR_MASK GENMASK(47, PAGE_SHIFT) -#define KVM_PTE_ADDR_51_48 GENMASK(15, 12) - #define KVM_PTE_LEAF_ATTR_LO GENMASK(11, 2) #define KVM_PTE_LEAF_ATTR_LO_S1_ATTRIDX GENMASK(4, 2) @@ -61,17 +57,6 @@ struct kvm_pgtable_walk_data { u64 end; }; -static u64 kvm_granule_shift(u32 level) -{ - /* Assumes KVM_PGTABLE_MAX_LEVELS is 4 */ - return ARM64_HW_PGTABLE_LEVEL_SHIFT(level); -} - -static u64 kvm_granule_size(u32 level) -{ - return BIT(kvm_granule_shift(level)); -} - #define KVM_PHYS_INVALID (-1ULL) static bool kvm_phys_is_valid(u64 phys) @@ -79,15 +64,6 @@ static bool kvm_phys_is_valid(u64 phys) return phys < BIT(id_aa64mmfr0_parange_to_phys_shift(ID_AA64MMFR0_PARANGE_MAX)); } -static bool kvm_level_supports_block_mapping(u32 level) -{ - /* - * Reject invalid block mappings and don't bother with 4TB mappings for - * 52-bit PAs. - */ - return !(level == 0 || (PAGE_SIZE != SZ_4K && level == 1)); -} - static bool kvm_block_mapping_supported(u64 addr, u64 end, u64 phys, u32 level) { u64 granule = kvm_granule_size(level); @@ -135,11 +111,6 @@ static u32 kvm_pgd_pages(u32 ia_bits, u32 start_level) return __kvm_pgd_page_idx(&pgt, -1ULL) + 1; } -static bool kvm_pte_valid(kvm_pte_t pte) -{ - return pte & KVM_PTE_VALID; -} - static bool kvm_pte_table(kvm_pte_t pte, u32 level) { if (level == KVM_PGTABLE_MAX_LEVELS - 1) @@ -151,16 +122,6 @@ static bool kvm_pte_table(kvm_pte_t pte, u32 level) return FIELD_GET(KVM_PTE_TYPE, pte) == KVM_PTE_TYPE_TABLE; } -static u64 kvm_pte_to_phys(kvm_pte_t pte) -{ - u64 pa = pte & KVM_PTE_ADDR_MASK; - - if (PAGE_SHIFT == 16) - pa |= FIELD_GET(KVM_PTE_ADDR_51_48, pte) << 48; - - return pa; -} - static kvm_pte_t kvm_phys_to_pte(u64 pa) { kvm_pte_t pte = pa & KVM_PTE_ADDR_MASK; -- 2.32.0.432.gabb21c7263-goog