Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2315587pxy; Tue, 3 Aug 2021 03:26:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxg4wWA0t7oV0sj+yP0VVKJGWXtQnAPKUNoPZbMdY/4SIJj/tW/qXdMuE32dZHmx7KojVD0 X-Received: by 2002:a02:7348:: with SMTP id a8mr18700352jae.116.1627986361928; Tue, 03 Aug 2021 03:26:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627986361; cv=none; d=google.com; s=arc-20160816; b=vgbNTMV2Z72wh0DOqC65ZIjVDZ9XTpD20Ha/ncvN0KitL2n7dPfIQNAnA1z8cnjyxM bQAuaq8QVL5vcAVYKuNyf6OxtaxpV3SqFTB9+Dt80EFQj1YtNsJz5+BbLbbkttkSGyop pVrwT7EC+RkWEQqB0mSEl1E5kbnnmL51TGVCZXFY2LRc6vcD7/GCqO99jKZM3vCI3vw3 PZIXYhsBXRRcZApLwhDY56p6GYdeCCG3XqLaPJaNgR9Z7y5tJxxAUlbfdGzF3UIW7UeM Kzg+jRGXG7UvuEr3BbpbvHoGpyIqeX2KG6GnxxLuRcJaoAbq48u6ldMCd2kx5utQvYUs hdjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=d6Nsv/xNSHs2Om+wxrSlYuqNQWvEFvnUhoy5ThkMx0Q=; b=uZygO3j9XO0znEF56uRstV9vR5dzG7cIHeSsPRFccIUBq7EJb50TCmhd+JBy/eDx4x HBIeMrj6IWTYzQ+AJ6LS3COwv7Ch0dgHpggSeIxfWO1s92mibfz+gXSxZw7gA+3yGI4m fwK7MmzUGPXBuldxPGou/8UxXs0w0sz+yy5S9jPtiuJuZYRFIlJPRXZ4o2bZ+KEnPohc rvjHrkoODRsV/Xa5xT1g972t9HEErOYAre+7RMjTfbQuoD7LQKPZ/Ac+9MjX+Yj+WTR7 wdiEMDRI7jThElX56sWinFID6jI7g8tGDAabLgjAxAkrRKsrmwz2ZaoMmFFqfmHA/Oi8 Ylcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=FP0D12uU; 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 b15si15848662ilv.151.2021.08.03.03.25.47; Tue, 03 Aug 2021 03:26:01 -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=FP0D12uU; 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 S235385AbhHCKYi (ORCPT + 99 others); Tue, 3 Aug 2021 06:24:38 -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-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!