From patchwork Fri Apr 15 21:58:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 12815444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 9FEDFC433F5 for ; Fri, 15 Apr 2022 22:00:28 +0000 (UTC) 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:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=ynqN6Obptrkgz/ZqOcdeGY4ZvY0jvLFXY+NHlgK0olk=; b=TOmYzubbI8q0bltT5z0hM2Z+WJ zZYf2+sfqwUg6J7OOi0rWaMXvf8oPLxnQzdXuUq/R4zgw4NBciHluvIZoddid/NlJQkN40mVJJk77 rcr4A8ZiqVIERyuIin4C6vaC1//uWbJCHwzqq373Ly2m7WjEixlXODEqQRmfua/I07WVYhx0i0r6L GEXoXRDCzF0tSo90Kf3yTWehwSF4TCAJFZVMFQg3lPNCm+YuZMn/f8TuPU9UABizLdVJY6cmb27Dv yLQByDFUwXwZbF6ULpD3a2NbJSv1Kv0ydVi0HUxK+xnIRUS06hmVjK6Nw1Aq5dCLcRAD0yOf4vejq qEEfWMfQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfTyR-00BS9k-3I; Fri, 15 Apr 2022 21:59:27 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nfTyB-00BRyx-Pd for linux-arm-kernel@lists.infradead.org; Fri, 15 Apr 2022 21:59:13 +0000 Received: by mail-yb1-xb49.google.com with SMTP id q142-20020a25d994000000b00641d23dbeb9so7336150ybg.9 for ; Fri, 15 Apr 2022 14:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=Tyg2Q1CJQYh6kqJKn5I8WsZWhqynGf1zv3GZVnyVrPI=; b=bs/o3a1yI+YtQKTec7tfylXXQu4M6ad2QWFFL62JX+gXbwqO9FEus3pkH+ThX+JPAr JPEPreeCxgkfcEjZxuDSMTLLZUbJYuMNUMiPP28ZaBVQA8xAoGGJwyWWqjUTVOr9w+H1 scbsRRQ4oV/0Ko6nzOrL8D58Z+zUc2quNieeYqKnL4/2GddH6EUAGmW8TUmhdokw0buR c0G9PrlnzO6Zct/R0EMtBthEbtbkFluRFT3bcL6Benpi1sBm1BLEUooH5TD8OFDM9SNB FGX1+tPIQqSDfmOl4/bgqfhcbkyjAEMmpAUImOqM0PuNfNbC+i60/UI9Bsp0mp7hYMtn Jqnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Tyg2Q1CJQYh6kqJKn5I8WsZWhqynGf1zv3GZVnyVrPI=; b=gQvYwX4vwvHf2SsMWnebRI/2dx3771eLvYxvi5nfnmRUzCQQvb0zoEEMtqKq2kunW8 VcZbfI0roExPudMPwBpa5oWwQ12Ym1jH4xMegAoN8Uhjn0ZcoOkYIeyFBST7WR6s+cOV BklfNOb8VjkOVhuw3L0VE8dF25SGt6GHge0SlRzY2JfdOcnuaH/+erRxiV/TDPHP/LDf 10HQg42FgvowT4/rJcsfC1slEwssLhutYiz433217vW1IJEosGTXNL50CjWVvMSZ1Uci lPVw7Ekh9f4nIsV7JZN2T2dU6msWi/tphkzRFhHM945cx06HNfxYDk/mrz2OQALTJp0u vUXQ== X-Gm-Message-State: AOAM533U3ODWFbGMw/V78nmkhEfM2VkeoQQkiWZnVfHhfDo8t221aaVN CrcpgsI6utcoWULH9FGixjzQUkVAIr8= X-Google-Smtp-Source: ABdhPJxEvl0U3CkvkcrBAn3HsWtsYmV0z/JZVUMkoVOPtU1p1JiWR679eaZiC7C8eGZtheHJa4oZ8Gi2BLk= X-Received: from oupton.c.googlers.com ([fda3:e722:ac3:cc00:2b:ff92:c0a8:404]) (user=oupton job=sendgmr) by 2002:a05:6902:544:b0:641:4007:1da8 with SMTP id z4-20020a056902054400b0064140071da8mr1070971ybs.195.1650059949262; Fri, 15 Apr 2022 14:59:09 -0700 (PDT) Date: Fri, 15 Apr 2022 21:58:45 +0000 In-Reply-To: <20220415215901.1737897-1-oupton@google.com> Message-Id: <20220415215901.1737897-2-oupton@google.com> Mime-Version: 1.0 References: <20220415215901.1737897-1-oupton@google.com> X-Mailer: git-send-email 2.36.0.rc0.470.gd361397f0d-goog Subject: [RFC PATCH 01/17] KVM: arm64: Directly read owner id field in stage2_pte_is_counted() From: Oliver Upton To: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org, Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , linux-arm-kernel@lists.infradead.org, Peter Shier , Ricardo Koller , Reiji Watanabe , Paolo Bonzini , Sean Christopherson , Ben Gardon , David Matlack , Oliver Upton X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220415_145911_867628_2771F17A X-CRM114-Status: UNSURE ( 9.62 ) X-CRM114-Notice: Please train this message. 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org A subsequent change to KVM will make use of additional bits in invalid ptes. Prepare for said change by explicitly checking the valid bit and owner fields in stage2_pte_is_counted() Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index 2cb3867eb7c2..e1506da3e2fb 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -172,6 +172,11 @@ static kvm_pte_t kvm_init_invalid_leaf_owner(u8 owner_id) return FIELD_PREP(KVM_INVALID_PTE_OWNER_MASK, owner_id); } +static u8 kvm_invalid_pte_owner(kvm_pte_t pte) +{ + return FIELD_GET(KVM_INVALID_PTE_OWNER_MASK, pte); +} + static int kvm_pgtable_visitor_cb(struct kvm_pgtable_walk_data *data, u64 addr, u32 level, kvm_pte_t *ptep, enum kvm_pgtable_walk_flags flag) @@ -679,7 +684,7 @@ static bool stage2_pte_is_counted(kvm_pte_t pte) * encode ownership of a page to another entity than the page-table * owner, whose id is 0. */ - return !!pte; + return kvm_pte_valid(pte) || kvm_invalid_pte_owner(pte); } static void stage2_put_pte(kvm_pte_t *ptep, struct kvm_s2_mmu *mmu, u64 addr,