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=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL 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 454A3C4338F for ; Mon, 26 Jul 2021 09:29:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2EA9C60F4E for ; Mon, 26 Jul 2021 09:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233176AbhGZItS (ORCPT ); Mon, 26 Jul 2021 04:49:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233213AbhGZItG (ORCPT ); Mon, 26 Jul 2021 04:49:06 -0400 Received: from mail-qt1-x84a.google.com (mail-qt1-x84a.google.com [IPv6:2607:f8b0:4864:20::84a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F4EAC0613D5 for ; Mon, 26 Jul 2021 02:29:34 -0700 (PDT) Received: by mail-qt1-x84a.google.com with SMTP id l7-20020ac848c70000b0290252173fe79cso4076845qtr.2 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=hip17ejCzOZH8vwZArEv94PbuKl8unhlk3WIK9iIAKPJNLKh0bMSiaT8GXPkLkqyA9 pVcLyqbf/dzGvVOhWIwvUJPbLQ86yRy4ok/IPZ+jjK8nztIUjhptEckFL7AB1bl2rjpB 79J2JNz4PKzJG7HrbbP5O/1PeeeCcOrEoIgKlcjuDOP6JK8/PZfesySor86P4ZxQtRnu NYgawosgojX/yvJsNhnt719I9CYTCBpCnBElkDOBSkF/gRkIVx2rj6Pfj2gV9HGO6rGs 93FOSB3iaxMqzsjrMZt8y4pHmySx1gjbNZ6jXfKvTQXaFRabZ/KdpVqJ/egswcYQhJXY FriQ== X-Gm-Message-State: AOAM532hvF3D/zGprUzUKf8KoxYyT8dMW2o2KdPXFoLUnB1wUE5UiZbH cR3gVHYDnmuVEqMdJ6OD7NKow7N6eJSJ 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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; -- 2.32.0.432.gabb21c7263-goog 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=-16.5 required=3.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED,DKIM_INVALID,DKIM_SIGNED,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 1771EC432BE for ; Mon, 26 Jul 2021 09:29:39 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id C0ECE60E09 for ; Mon, 26 Jul 2021 09:29:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C0ECE60E09 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 7102F49E72; Mon, 26 Jul 2021 05:29:38 -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 jxVjm4I+Hl1G; Mon, 26 Jul 2021 05:29:37 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id A59A94A523; Mon, 26 Jul 2021 05:29:36 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 2E3F149E5F for ; Mon, 26 Jul 2021 05:29:36 -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 dROudFs7TtM0 for ; Mon, 26 Jul 2021 05:29:35 -0400 (EDT) Received: from mail-qt1-f201.google.com (mail-qt1-f201.google.com [209.85.160.201]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id B8F8A4B0B1 for ; Mon, 26 Jul 2021 05:29:33 -0400 (EDT) Received: by mail-qt1-f201.google.com with SMTP id f9-20020a05622a1a09b02902615523e725so3981301qtb.21 for ; Mon, 26 Jul 2021 02:29:33 -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=gH/a5coK9pkeMnqd3Z68KaC84b3O0A/qxfNPG42agFIo6RDpFJQsnOdyDT8fZpRkrh jVFpTU5lDmXlxCa/y8ynbEpJgHhesYM768BKZj8iLwOIr/zmqY9+SRpZb56oGxNz+Xbx XEqFcUzWSjiFw3uK0Pea2+KIw8obkigCxxqVr4jGR7ZMi7HzOVET7dAgGpDdO9V76G1W sAgyDkuhJL5I2ZXHWM1Yn+MY37qhYusN7C7BJYN53cIa91L0AvIHFVQPq/nTih5wUQpm zS1US5u0eBg10SfybqE8jWfmmdGEfi9hb9eWBHkI0EuJi9fTVEMjBUMkqr9Abv+0zmqh UgyQ== X-Gm-Message-State: AOAM531F23kDQrEQc9R+O6c6Tg297Dzo66+VcAF4tXen2Zy+T4t1bZqM HgEJkqtV02uVP8UcwsoCtMcsk+Ezp9l/ 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: qwandor@google.com, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org, kernel-team@android.com 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 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; -- 2.32.0.432.gabb21c7263-goog _______________________________________________ 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=-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: , 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 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; -- 2.32.0.432.gabb21c7263-goog _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel