Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3803704pxb; Tue, 26 Jan 2021 05:21:11 -0800 (PST) X-Google-Smtp-Source: ABdhPJzY51BDE3gDqEd2ta2n69tl7sMIcXaQphnYkrLwXW3yCA657U+nu3yf2ZphJCMrncV3U+gc X-Received: by 2002:a05:6402:35ca:: with SMTP id z10mr4667017edc.174.1611667271820; Tue, 26 Jan 2021 05:21:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611667271; cv=none; d=google.com; s=arc-20160816; b=hFB8OtWVlSwh3yDpMAj2O9dPfTxVNI1HQ1h9YCSHQ5sLOpmzjxBguxgz0wPzMF0wBO ekvO3yoMnCCOYLeb3UCklm3swDmtn8kEVU1b0Hhpu5Pn3p3OTqDm84Zd1kWf1tT3gSb9 R6RBfpddKcFmhsnnUQlHpVtGO5gUP9e0wLgIrrH2+qUYThRbE6GMRz9IiZPOg0abxZ2a DLTx8sbJU0HYnh1+0zka8kozBU0+xJXiQaukaP62/j1I9+q1WOyw4VtIEXaYDYc/S6sy pM8qB3rXLbOgSzJ0srKGytHVChdhV/Q7wBoFBANp9dEVzp0dCygh2rbVWmh9kCsyeQw5 w7OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=RfP9pi8kzmCq78L5eKbzYxV5sse+/L4fnWumPChnsIw=; b=sSVUhZwKWZRp2GLXX20X2SfIUzGPpHKcm8fvxdzBxvuib6vk61ZrxUHcLcH3O+xe7v p3FIN7D+2BSMdOVqc6dsbs0GAurHsi7dzQfKBg3O/kudrUvQljZW2TswgzRyCyETD+hU MIWctkkMFjdmJlQ3PjTEzi6cWy/xhrRN1DudpWofcvcrxMIta+GECZnfGWcspMEUqXHn I1ywdUYZ3/CzzS33XnT7KLbFeF5POV50z6ZfXh5bAtwQOw53eKYZHGnF75SdNT0vmvUz fPGEuJdcOaEMMzcdPMaF4wjTaY5ae0KsT5Asqu4+/ggyJqRjhtiygBTyfPzIKoXOe+Q2 QvuQ== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l23si8572912edr.523.2021.01.26.05.20.47; Tue, 26 Jan 2021 05:21:11 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392633AbhAZNRu (ORCPT + 99 others); Tue, 26 Jan 2021 08:17:50 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:11506 "EHLO szxga05-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391788AbhAZMp7 (ORCPT ); Tue, 26 Jan 2021 07:45:59 -0500 Received: from DGGEMS412-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4DQ5yR1m3szjDds; Tue, 26 Jan 2021 20:43:59 +0800 (CST) Received: from DESKTOP-5IS4806.china.huawei.com (10.174.184.42) by DGGEMS412-HUB.china.huawei.com (10.3.19.212) with Microsoft SMTP Server id 14.3.498.0; Tue, 26 Jan 2021 20:45:03 +0800 From: Keqian Zhu To: , , , , Marc Zyngier , Will Deacon , Catalin Marinas CC: Alex Williamson , Kirti Wankhede , Cornelia Huck , Mark Rutland , James Morse , Robin Murphy , Suzuki K Poulose , , , , , Subject: [RFC PATCH 3/7] kvm: arm64: Add level_apply parameter for stage2_attr_walker Date: Tue, 26 Jan 2021 20:44:40 +0800 Message-ID: <20210126124444.27136-4-zhukeqian1@huawei.com> X-Mailer: git-send-email 2.8.4.windows.1 In-Reply-To: <20210126124444.27136-1-zhukeqian1@huawei.com> References: <20210126124444.27136-1-zhukeqian1@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.184.42] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order to change PTEs of some specific levels, the level_apply parameter can be used as a level mask. This has no fuctional change for current code. Signed-off-by: Keqian Zhu --- arch/arm64/kvm/hyp/pgtable.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 4915ba35f93b..0f8a319f16fe 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -734,6 +734,7 @@ struct stage2_attr_data { kvm_pte_t attr_clr; kvm_pte_t pte; u32 level; + u32 level_apply; }; static int stage2_attr_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, @@ -743,6 +744,9 @@ static int stage2_attr_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, kvm_pte_t pte = *ptep; struct stage2_attr_data *data = arg; + if (!(data->level_apply & BIT(level))) + return 0; + if (!kvm_pte_valid(pte)) return 0; @@ -753,14 +757,15 @@ static int stage2_attr_walker(u64 addr, u64 end, u32 level, kvm_pte_t *ptep, static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr, u64 size, kvm_pte_t attr_set, - kvm_pte_t attr_clr, kvm_pte_t *orig_pte, - u32 *level) + kvm_pte_t attr_clr, u32 level_apply, + kvm_pte_t *orig_pte, u32 *level) { int ret; kvm_pte_t attr_mask = KVM_PTE_LEAF_ATTR_LO | KVM_PTE_LEAF_ATTR_HI; struct stage2_attr_data data = { .attr_set = attr_set & attr_mask, .attr_clr = attr_clr & attr_mask, + .level_apply = level_apply, }; struct kvm_pgtable_walker walker = { .cb = stage2_attr_walker, @@ -783,7 +788,7 @@ static int stage2_update_leaf_attrs(struct kvm_pgtable *pgt, u64 addr, int kvm_pgtable_stage2_wrprotect(struct kvm_pgtable *pgt, u64 addr, u64 size) { return stage2_update_leaf_attrs(pgt, addr, size, 0, - KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, + KVM_PTE_LEAF_ATTR_LO_S2_S2AP_W, -1, NULL, NULL); } @@ -791,7 +796,7 @@ kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) { kvm_pte_t pte = 0; stage2_update_leaf_attrs(pgt, addr, 1, KVM_PTE_LEAF_ATTR_LO_S2_AF, 0, - &pte, NULL); + -1, &pte, NULL); dsb(ishst); return pte; } @@ -800,7 +805,7 @@ kvm_pte_t kvm_pgtable_stage2_mkold(struct kvm_pgtable *pgt, u64 addr) { kvm_pte_t pte = 0; stage2_update_leaf_attrs(pgt, addr, 1, 0, KVM_PTE_LEAF_ATTR_LO_S2_AF, - &pte, NULL); + -1, &pte, NULL); /* * "But where's the TLBI?!", you scream. * "Over in the core code", I sigh. @@ -813,7 +818,7 @@ kvm_pte_t kvm_pgtable_stage2_mkold(struct kvm_pgtable *pgt, u64 addr) bool kvm_pgtable_stage2_is_young(struct kvm_pgtable *pgt, u64 addr) { kvm_pte_t pte = 0; - stage2_update_leaf_attrs(pgt, addr, 1, 0, 0, &pte, NULL); + stage2_update_leaf_attrs(pgt, addr, 1, 0, 0, -1, &pte, NULL); return pte & KVM_PTE_LEAF_ATTR_LO_S2_AF; } @@ -833,7 +838,7 @@ int kvm_pgtable_stage2_relax_perms(struct kvm_pgtable *pgt, u64 addr, if (prot & KVM_PGTABLE_PROT_X) clr |= KVM_PTE_LEAF_ATTR_HI_S2_XN; - ret = stage2_update_leaf_attrs(pgt, addr, 1, set, clr, NULL, &level); + ret = stage2_update_leaf_attrs(pgt, addr, 1, set, clr, -1, NULL, &level); if (!ret) kvm_call_hyp(__kvm_tlb_flush_vmid_ipa, pgt->mmu, addr, level); return ret; -- 2.19.1