From patchwork Mon Aug 9 15:24:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12426819 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=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT 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 3E47AC4338F for ; Mon, 9 Aug 2021 15:33:09 +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 E82876101E for ; Mon, 9 Aug 2021 15:33:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org E82876101E 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: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=iaExK6vqDLKGVwC3u1PAYYbrPYicc+mkAHdX08h709o=; b=N1/1PrjKQLPNOIE1IdaEHlhPSD 4Y8sxBRelF6dVUeXJLx9Jc6vfjFMM/Egd4JkjbN7dSWR+0pKwoJFQ0rAUk9QfoU0TAP904c19L801 zY2nrj4hCoByJ53dQFJzLgvVJ6OO0jrWnGzGIRGyoOdv0CYuBhId6m7B8bSdBmuxyBtBbNeIu5tYI 1vYbVbRCBli7ozf6HtLTw6jCXbXVMnGCWW7+UI0Eteoi+29+543X6QuUiAJ5GbAnJVo3FbDeaWJKl eNxXEoNYil7v8bbIAjijSQGmEYjqfNsCcbls88x3LCU55gRq5I2yx69ENtrO6DWpj53Tg/YQuQgjA E1/FyDgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD7Ed-001AT1-G7; Mon, 09 Aug 2021 15:30:40 +0000 Received: from mail-qv1-xf4a.google.com ([2607:f8b0:4864:20::f4a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD79T-0017x4-BD for linux-arm-kernel@lists.infradead.org; Mon, 09 Aug 2021 15:25:21 +0000 Received: by mail-qv1-xf4a.google.com with SMTP id k7-20020ad453c70000b02902f36ca6afdcso8293661qvv.7 for ; Mon, 09 Aug 2021 08:25:18 -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=8jz2lJsOdyZcDtlCHC3Dvx0yZKTs2N3b55wAk/v95ow=; b=BDFa2yN6cmKJG3x9zJSFyiSyGXrWwbQI3EkRXEyAoiDsNiZxnCuM7yr8Oa4sS4dxId 5eKr+FKgGlQq97sho5QfjNNpY4QVEgOwGe4qnto8+PH1sPYKxvsSFFEWd/WmFfbdUvkD c3sroI1akznW1wvpagXKal01dux4IP23CQRoyQzKlB2Hq7vZwlRmeuzMiiGUULtM74EO vqk/PboQA93VAnMy1vjV9PrMoZNR67MMoGR8eoMC8skkuWKBSfLRX65XrYlx1k9PzQEL B4Vu9eiDVi86Co2QUmAnVC43oq9HYU5EMtVUKZQVLmLRE/lJ3PSGixyaFvXfy8rmzq2H k/VQ== 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=8jz2lJsOdyZcDtlCHC3Dvx0yZKTs2N3b55wAk/v95ow=; b=E0PYh9Qa5eFcqhJrJ/jEI4NCK3wD/Iqgd+eBB4Lit1ufrT+gwSDrxoQIt8gECfJtpz gdh3w5pAuWELXKRJPAz5/CooEdz7GfE3xCcF2DSsqKUxHAaMw+ZGAxDCZsaI187IhSdZ y4UPfwlT9ScQ8swIssPt+OOuYdCsy03A7GLEAhV/CZ1FqMsM6nR30aOVYzIkiNCIz1Pp r2eTHvjsRj8yg2ZxMYbwqUJ1OUNMmHsEqjOdSg0Ettur+d+2OPGT1JyKiL92pQ5fd/UG LjLBCrNEcoBSpAUAVVn/U/N29njlRcoJh/XXlJg4NqFKgSVaHB96/hM9QTcE8d4W7xj0 XINQ== X-Gm-Message-State: AOAM531NQia/NVsezwHjg/+wf1Ro2B4l+Ryj2bos8uaj4kU4y4DpXpMG N3hcp2gXdvNeUY9MOVD1Nohmr7PZfZqs X-Google-Smtp-Source: ABdhPJz2l1NOBwMrE26TsCA7occvb2o9beTqoSppx2h3dHXwe0dIzSOg5MwgreJKvwJvtlmSCeojgXOCjH28 X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:b0e8:d460:758b:a0ae]) (user=qperret job=sendgmr) by 2002:a05:6214:10c4:: with SMTP id r4mr24445444qvs.58.1628522717738; Mon, 09 Aug 2021 08:25:17 -0700 (PDT) Date: Mon, 9 Aug 2021 16:24:39 +0100 In-Reply-To: <20210809152448.1810400-1-qperret@google.com> Message-Id: <20210809152448.1810400-13-qperret@google.com> Mime-Version: 1.0 References: <20210809152448.1810400-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v4 12/21] KVM: arm64: Add helpers to tag shared pages in SW bits 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, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210809_082519_444901_CC1AC6F4 X-CRM114-Status: GOOD ( 12.82 ) 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 We will soon start annotating shared pages in page-tables in nVHE protected mode. Define all the states in which a page can be (owned, shared and owned, shared and borrowed), and provide helpers allowing to convert this into SW bits annotations using the matching prot attributes. Reviewed-by: Fuad Tabba Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h index 9c227d87c36d..87b1690c439f 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -12,6 +12,32 @@ #include #include +/* + * SW bits 0-1 are reserved to track the memory ownership state of each page: + * 00: The page is owned exclusively by the page-table owner. + * 01: The page is owned by the page-table owner, but is shared + * with another entity. + * 10: The page is shared with, but not owned by the page-table owner. + * 11: Reserved for future use (lending). + */ +enum pkvm_page_state { + PKVM_PAGE_OWNED = 0ULL, + PKVM_PAGE_SHARED_OWNED = KVM_PGTABLE_PROT_SW0, + PKVM_PAGE_SHARED_BORROWED = KVM_PGTABLE_PROT_SW1, +}; + +#define PKVM_PAGE_STATE_PROT_MASK (KVM_PGTABLE_PROT_SW0 | KVM_PGTABLE_PROT_SW1) +static inline enum kvm_pgtable_prot pkvm_mkstate(enum kvm_pgtable_prot prot, + enum pkvm_page_state state) +{ + return (prot & ~PKVM_PAGE_STATE_PROT_MASK) | state; +} + +static inline enum pkvm_page_state pkvm_getstate(enum kvm_pgtable_prot prot) +{ + return prot & PKVM_PAGE_STATE_PROT_MASK; +} + struct host_kvm { struct kvm_arch arch; struct kvm_pgtable pgt;