From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D47E2C4338F for ; Tue, 3 Aug 2021 10:24:22 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 62DD960F58 for ; Tue, 3 Aug 2021 10:24:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 62DD960F58 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 044DA40799; Tue, 3 Aug 2021 06:24:22 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Authentication-Results: mm01.cs.columbia.edu (amavisd-new); dkim=softfail (fail, message has been altered) header.i=@google.com Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rLDy4r+INt9C; Tue, 3 Aug 2021 06:24:20 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C0162406AD; Tue, 3 Aug 2021 06:24:20 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id C6E624064F for ; Tue, 3 Aug 2021 06:24:19 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0RoNfujwOcUB for ; Tue, 3 Aug 2021 06:24:18 -0400 (EDT) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 827AC40629 for ; Tue, 3 Aug 2021 06:24:18 -0400 (EDT) Received: by mail-wr1-f46.google.com with SMTP id z4so24768868wrv.11 for ; Tue, 03 Aug 2021 03:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=FP0D12uUpP5OBvBJhAyl2dhq/xIpjHa4hZWkq4WRNfgxNtiPI5C6WPYX+SGVeC3ukl ZWEGnBrN5n6lwuVMkQyX0O7o8hsbO7aJ8dYH1ye3Tpp7c4cGB/2sVFrXYy12qm5rGvds hkTc+cakkXC9bcPjo4laVstTV0GDVZrfNNWrsIMRP+Tau4jPgy2iP2jvKkZiDWjfFrFy cP6Sozo7M0T5i08TOHBQfZd/TJI5Es/WHVej0aFyjpVZQZC9d2Fe7bnTPaB8Gy3tB//n ETrsOto9MjuxzgoSsMaWII+VfYTMe60WGl3u0yO5efg66bp2CHBuitvheec6vOCRi9JF UI9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=BeakNtRn+CJw/m8h6o6J9frmt6QYsWlGz+lsPhxMYeh/S62ep/YJM1pIx2fO6aXGqF 1L69DGbD+8e8vxwN16LrnIj7nUObGPDKsrbdzSdf9itfB9twSyhOUDRSxcdkCZ+kDNRG erIDm7uy2hbleLVqKYZsCFqgL02YRYjx6sqzGf6suBYWi6WsL60DYlf0aoZpfhuc39xi jnbbmDgxF310pR/bjJyuxhduxdK3jkoXnDnNkxtSGBwgxaIQCQ30KtLM9lyMsQm1TACd 2cSbWLQx1c7OOYjCMnvck0AopebFET18tOOtzLofr4nZrXY0OnRJ9I0cMWOJNnbFBbrZ xz2A== X-Gm-Message-State: AOAM5322BhXxT5CMVCIqVv5gsV2lKrnBnHhYCNIrxgtVGff31g2GIeoZ iyVwiQDLOONAVa3wpOoGbh7XsA== X-Google-Smtp-Source: ABdhPJwblvZME7yKQlNor7Ndnl8b41R6jAh8T6Km7UHNqfvDgBQx1oplfzKTG7fCFMoS/YBxs1eocA== X-Received: by 2002:adf:f2cd:: with SMTP id d13mr22244889wrp.315.1627986257474; Tue, 03 Aug 2021 03:24:17 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:754:7d1b:7303:129a]) by smtp.gmail.com with ESMTPSA id v15sm2179876wmj.39.2021.08.03.03.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 03:24:17 -0700 (PDT) Date: Tue, 3 Aug 2021 11:24:14 +0100 From: Quentin Perret To: Fuad Tabba Subject: Re: [PATCH v3 16/21] KVM: arm64: Enable retrieving protections attributes of PTEs Message-ID: References: <20210729132818.4091769-1-qperret@google.com> <20210729132818.4091769-17-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Cc: kernel-team@android.com, qwandor@google.com, maz@kernel.org, linux-kernel@vger.kernel.org, catalin.marinas@arm.com, will@kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu On Monday 02 Aug 2021 at 16:52:49 (+0200), Fuad Tabba wrote: > Hi Quentin, > > On Thu, Jul 29, 2021 at 3:29 PM Quentin Perret wrote: > > > > Introduce helper functions in the KVM stage-2 and stage-1 page-table > > manipulation library allowing to retrieve the enum kvm_pgtable_prot of a > > PTE. This will be useful to implement custom walkers outside of > > pgtable.c. > > > > Signed-off-by: Quentin Perret > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 20 +++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 37 ++++++++++++++++++++++++++++ > > 2 files changed, 57 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index d5ca9b6ce241..7ff9f52239ba 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -505,4 +505,24 @@ int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, > > */ > > int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr, > > kvm_pte_t *ptep, u32 *level); > > + > > +/** > > + * kvm_pgtable_stage2_pte_prot() - Retrieve the protection attributes of a > > + * stage-2 Page-Table Entry. > > + * @pte: Page-table entry > > + * > > + * Return: protection attributes of the page-table entry in the enum > > + * kvm_pgtable_prot format. > > + */ > > +enum kvm_pgtable_prot kvm_pgtable_stage2_pte_prot(kvm_pte_t pte); > > + > > +/** > > + * kvm_pgtable_hyp_pte_prot() - Retrieve the protection attributes of a stage-1 > > + * Page-Table Entry. > > + * @pte: Page-table entry > > + * > > + * Return: protection attributes of the page-table entry in the enum > > + * kvm_pgtable_prot format. > > + */ > > +enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte); > > #endif /* __ARM64_KVM_PGTABLE_H__ */ > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index 1915489bb127..a6eda8f23cb6 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -363,6 +363,26 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > > return 0; > > } > > > > +enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte) > > +{ > > + enum kvm_pgtable_prot prot = pte & KVM_PTE_LEAF_ATTR_HI_SW; > > + u32 ap; > > + > > + if (!kvm_pte_valid(pte)) > > + return prot; > > + > > + if (!(pte & KVM_PTE_LEAF_ATTR_HI_S1_XN)) > > + prot |= KVM_PGTABLE_PROT_X; > > + > > + ap = FIELD_GET(KVM_PTE_LEAF_ATTR_LO_S1_AP, pte); > > + if (ap == KVM_PTE_LEAF_ATTR_LO_S1_AP_RO) > > + prot |= KVM_PGTABLE_PROT_R; > > + else if (ap == KVM_PTE_LEAF_ATTR_LO_S1_AP_RW) > > + prot |= KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W; > > nit: why not use the freshly minted KVM_PGTABLE_PROT_RW? No good reason, I'll fix that up, thanks! _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9CF42C4338F for ; Tue, 3 Aug 2021 10:26:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 70F5E60238 for ; Tue, 3 Aug 2021 10:26:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 70F5E60238 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=vWh2ADSSrGn1xvP1g4fUVHnstRu8QyIxc6A9bu1ITV4=; b=SRvrkALcm/jb4D GjoYDFOtdi0jwUa8ut4qPE6Vs5m+wakk3+q2Di3kPzAXi9V+QICAREIRyiwLWki0VPSfVj/nkM/TL VoB+8WpBu/EIpFokjlur3RdDBVPS8EAm9cM+UWSKRakl7tU8NCzQaedWWaeQhMZorPTAVNY+0EuYm XMS+bZQqpfHhFULHDj280q7g/4+c0gEuXKjkMGxjQ7FAiOPxqxG4HZbvnVFUqfsYwi2rfqEgaP06g 6M9JQyf8jrAQF1taGT4p+bKsYqEqCLlHoPYCfkruBkdCK7n1RRvSeMtB0RS/lAPgjxlgkiRq91DRl q+xkz5ZvUaMSynweCmyQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAraw-001zhh-TD; Tue, 03 Aug 2021 10:24:23 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mAras-001zg5-R2 for linux-arm-kernel@lists.infradead.org; Tue, 03 Aug 2021 10:24:20 +0000 Received: by mail-wr1-x42a.google.com with SMTP id m12so19955797wru.12 for ; Tue, 03 Aug 2021 03:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=FP0D12uUpP5OBvBJhAyl2dhq/xIpjHa4hZWkq4WRNfgxNtiPI5C6WPYX+SGVeC3ukl ZWEGnBrN5n6lwuVMkQyX0O7o8hsbO7aJ8dYH1ye3Tpp7c4cGB/2sVFrXYy12qm5rGvds hkTc+cakkXC9bcPjo4laVstTV0GDVZrfNNWrsIMRP+Tau4jPgy2iP2jvKkZiDWjfFrFy cP6Sozo7M0T5i08TOHBQfZd/TJI5Es/WHVej0aFyjpVZQZC9d2Fe7bnTPaB8Gy3tB//n ETrsOto9MjuxzgoSsMaWII+VfYTMe60WGl3u0yO5efg66bp2CHBuitvheec6vOCRi9JF UI9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=ocHuW1dxKoTWLQBkBQlxbZn9CqO9f95CFSDfVj/QVxkP5Xf7oCk1yjEuc6rikjEsb6 tXKaJUQdWLbR9tXKFhjEHKfprvNTT1VC/Dt3DyfrMSfaHmHEx3ApLIiF26rqxr8CWxLN DLpESuiUkKkdhqZ8sS7GIDClY27MihsAlnlZWTH12O4SrGWqky1cpsZffe5eJZpmAD+l tfidGZMVHVtgobaneIOYjafncBOjcJdg1yAMpJnEhgvssy0O35Hf5CB7UVWCJsgMwlJn QIT1kK/IDSMecq2VtnDGxg6Wy2M+n6cRqCM5HvA0QUvlVCbndHPioj4jEiWVWOPrrsB9 Fxzw== X-Gm-Message-State: AOAM530CpVLQekJHcUXySnZ4k3Hvj0wuqjGNXlwsauNncZ6ho8EcPaIq 5IoiBZ+qCcE0Hn5vZ1073IApxQ== X-Google-Smtp-Source: ABdhPJwblvZME7yKQlNor7Ndnl8b41R6jAh8T6Km7UHNqfvDgBQx1oplfzKTG7fCFMoS/YBxs1eocA== X-Received: by 2002:adf:f2cd:: with SMTP id d13mr22244889wrp.315.1627986257474; Tue, 03 Aug 2021 03:24:17 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:754:7d1b:7303:129a]) by smtp.gmail.com with ESMTPSA id v15sm2179876wmj.39.2021.08.03.03.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 03:24:17 -0700 (PDT) Date: Tue, 3 Aug 2021 11:24:14 +0100 From: Quentin Perret To: Fuad Tabba Cc: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, dbrazdil@google.com, kernel-team@android.com Subject: Re: [PATCH v3 16/21] KVM: arm64: Enable retrieving protections attributes of PTEs Message-ID: References: <20210729132818.4091769-1-qperret@google.com> <20210729132818.4091769-17-qperret@google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210803_032418_923542_5FB173DD X-CRM114-Status: GOOD ( 22.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Monday 02 Aug 2021 at 16:52:49 (+0200), Fuad Tabba wrote: > Hi Quentin, > > On Thu, Jul 29, 2021 at 3:29 PM Quentin Perret wrote: > > > > Introduce helper functions in the KVM stage-2 and stage-1 page-table > > manipulation library allowing to retrieve the enum kvm_pgtable_prot of a > > PTE. This will be useful to implement custom walkers outside of > > pgtable.c. > > > > Signed-off-by: Quentin Perret > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 20 +++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 37 ++++++++++++++++++++++++++++ > > 2 files changed, 57 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index d5ca9b6ce241..7ff9f52239ba 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -505,4 +505,24 @@ int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, > > */ > > int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr, > > kvm_pte_t *ptep, u32 *level); > > + > > +/** > > + * kvm_pgtable_stage2_pte_prot() - Retrieve the protection attributes of a > > + * stage-2 Page-Table Entry. > > + * @pte: Page-table entry > > + * > > + * Return: protection attributes of the page-table entry in the enum > > + * kvm_pgtable_prot format. > > + */ > > +enum kvm_pgtable_prot kvm_pgtable_stage2_pte_prot(kvm_pte_t pte); > > + > > +/** > > + * kvm_pgtable_hyp_pte_prot() - Retrieve the protection attributes of a stage-1 > > + * Page-Table Entry. > > + * @pte: Page-table entry > > + * > > + * Return: protection attributes of the page-table entry in the enum > > + * kvm_pgtable_prot format. > > + */ > > +enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte); > > #endif /* __ARM64_KVM_PGTABLE_H__ */ > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index 1915489bb127..a6eda8f23cb6 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -363,6 +363,26 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > > return 0; > > } > > > > +enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte) > > +{ > > + enum kvm_pgtable_prot prot = pte & KVM_PTE_LEAF_ATTR_HI_SW; > > + u32 ap; > > + > > + if (!kvm_pte_valid(pte)) > > + return prot; > > + > > + if (!(pte & KVM_PTE_LEAF_ATTR_HI_S1_XN)) > > + prot |= KVM_PGTABLE_PROT_X; > > + > > + ap = FIELD_GET(KVM_PTE_LEAF_ATTR_LO_S1_AP, pte); > > + if (ap == KVM_PTE_LEAF_ATTR_LO_S1_AP_RO) > > + prot |= KVM_PGTABLE_PROT_R; > > + else if (ap == KVM_PTE_LEAF_ATTR_LO_S1_AP_RW) > > + prot |= KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W; > > nit: why not use the freshly minted KVM_PGTABLE_PROT_RW? No good reason, I'll fix that up, thanks! _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.4 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FSL_HELO_FAKE, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1A5AC4338F for ; Tue, 3 Aug 2021 10:25:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D3F5960EFD for ; Tue, 3 Aug 2021 10:25:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235407AbhHCKZU (ORCPT ); Tue, 3 Aug 2021 06:25:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235377AbhHCKYa (ORCPT ); Tue, 3 Aug 2021 06:24:30 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0177DC061764 for ; Tue, 3 Aug 2021 03:24:19 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id p5so24762052wro.7 for ; Tue, 03 Aug 2021 03:24:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=FP0D12uUpP5OBvBJhAyl2dhq/xIpjHa4hZWkq4WRNfgxNtiPI5C6WPYX+SGVeC3ukl ZWEGnBrN5n6lwuVMkQyX0O7o8hsbO7aJ8dYH1ye3Tpp7c4cGB/2sVFrXYy12qm5rGvds hkTc+cakkXC9bcPjo4laVstTV0GDVZrfNNWrsIMRP+Tau4jPgy2iP2jvKkZiDWjfFrFy cP6Sozo7M0T5i08TOHBQfZd/TJI5Es/WHVej0aFyjpVZQZC9d2Fe7bnTPaB8Gy3tB//n ETrsOto9MjuxzgoSsMaWII+VfYTMe60WGl3u0yO5efg66bp2CHBuitvheec6vOCRi9JF UI9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=ZVm0fp1keQZOSOxxEJf0vneWk5edfEDGYPhyo7gipWV5kaxrvJpPWy4zRJG/5o2h+j l3p2rAtXcnaYaxUyezXzmx+PAXlDVY2Ia/yBtMkHzfqy390LNIwR3tDb6LmfZN7STKuV v02/5otPxU6ntoZF9cRRPC4PrLYV4EbO6z4fkShuXrQM3Z72NfvxeayWbP9iFXnjKB4s nlcN4e1JV1oD4/9nIv7JyQhKTzGa4waU4qyuJU9yHK2U/4YMLAQrYufFngrbOZVbRkVN wzOE5b/JeFpohkpgI8+rpd6PhMXlH99twVI/Vylev0cK2UrE6Hx15YiH9t3c+ArziGtt 5WnA== X-Gm-Message-State: AOAM533aGPw3Ma+qDZAJWjYTBYQiSx6nYkV6SzFhS7AAjsJZqHqTfrOt 02aYZCAlmkvH+wwIo4yYfMWl6g== X-Google-Smtp-Source: ABdhPJwblvZME7yKQlNor7Ndnl8b41R6jAh8T6Km7UHNqfvDgBQx1oplfzKTG7fCFMoS/YBxs1eocA== X-Received: by 2002:adf:f2cd:: with SMTP id d13mr22244889wrp.315.1627986257474; Tue, 03 Aug 2021 03:24:17 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:754:7d1b:7303:129a]) by smtp.gmail.com with ESMTPSA id v15sm2179876wmj.39.2021.08.03.03.24.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 03:24:17 -0700 (PDT) Date: Tue, 3 Aug 2021 11:24:14 +0100 From: Quentin Perret To: Fuad Tabba Cc: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, dbrazdil@google.com, kernel-team@android.com Subject: Re: [PATCH v3 16/21] KVM: arm64: Enable retrieving protections attributes of PTEs Message-ID: References: <20210729132818.4091769-1-qperret@google.com> <20210729132818.4091769-17-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Monday 02 Aug 2021 at 16:52:49 (+0200), Fuad Tabba wrote: > Hi Quentin, > > On Thu, Jul 29, 2021 at 3:29 PM Quentin Perret wrote: > > > > Introduce helper functions in the KVM stage-2 and stage-1 page-table > > manipulation library allowing to retrieve the enum kvm_pgtable_prot of a > > PTE. This will be useful to implement custom walkers outside of > > pgtable.c. > > > > Signed-off-by: Quentin Perret > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 20 +++++++++++++++ > > arch/arm64/kvm/hyp/pgtable.c | 37 ++++++++++++++++++++++++++++ > > 2 files changed, 57 insertions(+) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index d5ca9b6ce241..7ff9f52239ba 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -505,4 +505,24 @@ int kvm_pgtable_walk(struct kvm_pgtable *pgt, u64 addr, u64 size, > > */ > > int kvm_pgtable_get_leaf(struct kvm_pgtable *pgt, u64 addr, > > kvm_pte_t *ptep, u32 *level); > > + > > +/** > > + * kvm_pgtable_stage2_pte_prot() - Retrieve the protection attributes of a > > + * stage-2 Page-Table Entry. > > + * @pte: Page-table entry > > + * > > + * Return: protection attributes of the page-table entry in the enum > > + * kvm_pgtable_prot format. > > + */ > > +enum kvm_pgtable_prot kvm_pgtable_stage2_pte_prot(kvm_pte_t pte); > > + > > +/** > > + * kvm_pgtable_hyp_pte_prot() - Retrieve the protection attributes of a stage-1 > > + * Page-Table Entry. > > + * @pte: Page-table entry > > + * > > + * Return: protection attributes of the page-table entry in the enum > > + * kvm_pgtable_prot format. > > + */ > > +enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte); > > #endif /* __ARM64_KVM_PGTABLE_H__ */ > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index 1915489bb127..a6eda8f23cb6 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -363,6 +363,26 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > > return 0; > > } > > > > +enum kvm_pgtable_prot kvm_pgtable_hyp_pte_prot(kvm_pte_t pte) > > +{ > > + enum kvm_pgtable_prot prot = pte & KVM_PTE_LEAF_ATTR_HI_SW; > > + u32 ap; > > + > > + if (!kvm_pte_valid(pte)) > > + return prot; > > + > > + if (!(pte & KVM_PTE_LEAF_ATTR_HI_S1_XN)) > > + prot |= KVM_PGTABLE_PROT_X; > > + > > + ap = FIELD_GET(KVM_PTE_LEAF_ATTR_LO_S1_AP, pte); > > + if (ap == KVM_PTE_LEAF_ATTR_LO_S1_AP_RO) > > + prot |= KVM_PGTABLE_PROT_R; > > + else if (ap == KVM_PTE_LEAF_ATTR_LO_S1_AP_RW) > > + prot |= KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W; > > nit: why not use the freshly minted KVM_PGTABLE_PROT_RW? No good reason, I'll fix that up, thanks!