From patchwork Mon Jul 26 09:28:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12398943 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 40A31C4338F for ; Mon, 26 Jul 2021 09:35:50 +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 0B3A360E09 for ; Mon, 26 Jul 2021 09:35:50 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0B3A360E09 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=j39KdAxmArPZAmhY7kGlaOo7EWdX2DPzIjH+ekOsCPs=; b=bpPrWN3ay7BGzz5BSmfqzcRFxv xfCVsSDUYJZH9eZCMX+4pk5SQHMOKhv5bksXt93vsEfh71gTLgCe3/0twAQ4NWL6hhvhLqr85HPpC DSeMwY6Jbc8BFre8Kq+U+rgNU96pgBm3FNLlndUIdQbf2x7+dxfLfE9YatqU3tbiQ1vuYXNl7X+q2 zvWh9X+YSSno8sskuu1LF/PNfTnV/s+WT1KPXWQDNPU+XaqHYzJSCJSvOj3vvuFFgIDBy9DreQwtm 23jVkQO8u5zBCvqO2tqcH+J8u+SCQkc4eTEHuwCPQbXojeWLv/gq1dD3DXV0BiRNkKR08olSxNi7V axGl/Kyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7wzX-00ATMt-I6; Mon, 26 Jul 2021 09:33:43 +0000 Received: from mail-qt1-x849.google.com ([2607:f8b0:4864:20::849]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m7wvX-00ARaH-Fh for linux-arm-kernel@lists.infradead.org; Mon, 26 Jul 2021 09:29:36 +0000 Received: by mail-qt1-x849.google.com with SMTP id e19-20020ac84b530000b0290251f0b91196so4018590qts.14 for ; Mon, 26 Jul 2021 02:29:34 -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=oI1lsqd2Q7dxLS0xam0vuO1J8Xxzsd51ZvtsfH3kSqA=; b=bXUXb/i9hSD5qN+TC+k+TwbawB1Ioga3ua3ibJeKI8gHVrRfQF1zVfzZ9qUKUJWIZb D3xLOECrzB08csaTg6TGm2x6MiN2M0qkKt7aUpIzWlvypa7VgYw7HoaS8o9nwDLUc3Nt H/I3JOAjQfDHzXOk2iBvFyJl4Ofl/yegYHjGNrZWBdXPhk1D876uuHch99124AS6qus7 EeemZ0cg6jHhbWX/57lWGRwafDUed/QpP+m0HQ1U2ANbhgXhsZwGerOpdJs9Df1RiqXo uEtAXLQXFJZUQjutSGSIyRCOHeo6U82U5bsQSPmEcXs8Wfx1gjaZbyNisbC3A+TAs1WN NoOQ== 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=oI1lsqd2Q7dxLS0xam0vuO1J8Xxzsd51ZvtsfH3kSqA=; b=WGDGIFpWVuxLPMNylewAMdcy2UiD2/5EsxRMV0VINbL9UfUwFkKgA5XlS+VGPR5k7D /d99Rl/dYQaIlEdS6Jdhf6Otd4lrGeGaC8pXASTSct/XB1CHY3eDNWO16MnjrUEgI5FR KM6D4+Sr2qc0WmXQT017XbZYqVaWQVIpWeDlESd9XKeChM2U6Q5lzHHK10skXnUWWERS d4abeLS4xUB7EZKbtbv7GPC1ghK6TOoux/JYKVMmvr4qyKCWVtCNPr+uoOaM6XNKGEYC ZdEvBz9jKkBbLPXuBrqLQTD1SwMUadnPWWhrbiXWqG+79Wpwc3arhAQGsEaWbqQckd1/ F3Og== X-Gm-Message-State: AOAM532MF2fJqGqh+uh7b5QufFmN1ocDDeyaAp5BFGVy75IO9SR3Wm0T ffIIImm22mhzfSW4RB9tJftNdFuxrgVB X-Google-Smtp-Source: ABdhPJyCiJBcW6GLm8E7sXXL2J+ym67KXeRU47WQn21gBL8HZOPCdK1XRTVEI/TyzJ/m4gVul31p0IuTxjtT X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:23a0:2f14:433:e6cb]) (user=qperret job=sendgmr) by 2002:a0c:aacd:: with SMTP id g13mr2247331qvb.20.1627291773337; Mon, 26 Jul 2021 02:29:33 -0700 (PDT) Date: Mon, 26 Jul 2021 10:28:59 +0100 In-Reply-To: <20210726092905.2198501-1-qperret@google.com> Message-Id: <20210726092905.2198501-11-qperret@google.com> Mime-Version: 1.0 References: <20210726092905.2198501-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v2 10/16] 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, Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210726_022935_563934_A22B8AAE X-CRM114-Status: GOOD ( 12.72 ) 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. Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 27 +++++++++++++++++++ 1 file changed, 27 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..facbd9a7ab99 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h @@ -12,6 +12,33 @@ #include #include +/* + * SW bits 0-1 are reserved to track the memory ownership state of each page: + * 00: The page is owned solely 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;