Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp6098725pxv; Thu, 29 Jul 2021 06:30:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwekplbtPdejiNSopOmfe5Q29UUUDLATJ3Mmysr/eHxvk19fRs/TCAt+dZe0DeCHL/0pC29 X-Received: by 2002:a92:ca8f:: with SMTP id t15mr3744191ilo.262.1627565442634; Thu, 29 Jul 2021 06:30:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627565442; cv=none; d=google.com; s=arc-20160816; b=XXiN5t2SmuLYsnUI/tkuaPHLCdh93hvNfOURE7Ge6EDlraF7jMetn+vP3zrSm+9lVt a2jUwcj4xBQioG51ilDxNRPJ53oliXwsjKIJKHjNMnPbysVHnxgL1hUEC9PXB0zonZSH O7EzL9CFU9Ic82Xi0LU2d/6I9FZrYVDsxmxt7V+a0BXsj0OKFW1e2bt2pK5fen9M3BGY n59orenEiKbFPmN0215pgxvJjbmH16uYCsY0h8a1+8p3Nwn/UV1KvI91+6xHks6EnbWh IgZzHeX3u5DGMxKL00f+Aid9MhZf35dZOMiXYW+/Lqwxcz5q9YnI7GfeG93QHVpvpEbV SqgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=H72uhE5VGkDx1jb1MVcWxLaZfSQPWlRzbrWGol5Bg8o=; b=OCCgWqz2cqMCP4TDapwJCMc1DSnWRYPYS5dIOY5aG27hZ9jdRxDJ1mm1kv/lRPfuFp UwWKFJq5WRiqn7f9ka4H4lkqCNh9cfvwnxTnFyINtcrYG2Lxun9Ax2tQnqEDB6kkCb0+ yNf5THXgZsCkiP07ig+LVcBO1Cm2Qey9Tax90P29UxzIMbQeA21lubuKN6bp0Kaj6/Xt 9JfCMWaThdPbt2xFmgshD1oig9+MhOqliYyCOFyGBllnFKqi90uSiGnZCW71NYQ0XzsN 8k3UR8KODCI5pZCiZfs0tW7fiqqARnfjFiqcAMpDa50QfEeWfz/T+pGt0nJhrg8nezZ8 JkYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=HTncpCcF; 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 w33si3565521jal.65.2021.07.29.06.30.31; Thu, 29 Jul 2021 06:30:42 -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=HTncpCcF; 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 S237620AbhG2N3b (ORCPT + 99 others); Thu, 29 Jul 2021 09:29:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237687AbhG2N2z (ORCPT ); Thu, 29 Jul 2021 09:28:55 -0400 Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C0AAC061765 for ; Thu, 29 Jul 2021 06:28:52 -0700 (PDT) Received: by mail-wm1-x34a.google.com with SMTP id 132-20020a1c018a0000b029025005348905so1997772wmb.7 for ; Thu, 29 Jul 2021 06:28:52 -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=H72uhE5VGkDx1jb1MVcWxLaZfSQPWlRzbrWGol5Bg8o=; b=HTncpCcFrfYqsq+B0XVUZSJV3OsWsCbXAq0Nsc6wlmDYOhwALGBrA3jJ41pZG0qqMI BUp7QdvrQdj2zE8BkjdDej0plVEuMnXHWUQxTorC7+RLWrL1Cl5SNZOzSPQYcIPsiBfy PrIxNokt9gtSQCGyTC4CeE1TIB4Vpi45IPhQSXcZ31S+u0qfhpB+xXZJnFGTLgqBW/FK 8j7S1I+GtzmzNFPDXkOtQ4OpR5EBk196h65xM3EPu3FNApwn8htU1h7pYOsraR/C0MHV Et3C8vRAcLob23EWSpeVAA0PxgEvB3ZxKyeGA3rhHcr1KBj7OXeo6C86lTupLKh5WO3I vGjQ== 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=H72uhE5VGkDx1jb1MVcWxLaZfSQPWlRzbrWGol5Bg8o=; b=FZVF8xalg4cjxhPApNvihEO+UHnAP+cq2s3m8gh/4YVnybIDjW1HmvMmQqg3pkL0Zt UhJE2HctTt+eCJztT1RXa2QAv4Kfshp0nF0WmXYhYxlAwBBWFkV1QKGE9YK5tK5ofkXc pPru4rdbKNdKu9Sv8lHxpCq/j4l8S2m6z3OTGixRqggd0m/q6YIzQIKgG/u3HwfPpKPg Sype3sFBcBVRaDKV+ETZntMtfCT5dDat7XtNveeuZ7jjB6UGp47zLRqRImCHMRzrAmcq KpdeQWeTWYkOKvfE8amzUemi5dY+V8xcbuqdA+Cf3PfHK9fhcWg4ABpFLZ3HjF8hbBhJ 75oA== X-Gm-Message-State: AOAM531bFF7YBJb8rwu1cfNO3sXQZ/IkXX6EnyOc3PoGEC8DNQqLWKpI is3gbX2MaDMb6Bl5w1hPO2MFKaGuIrW7 X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:293a:bc89:7514:5218]) (user=qperret job=sendgmr) by 2002:a1c:a78a:: with SMTP id q132mr4804653wme.76.1627565330622; Thu, 29 Jul 2021 06:28:50 -0700 (PDT) Date: Thu, 29 Jul 2021 14:28:09 +0100 In-Reply-To: <20210729132818.4091769-1-qperret@google.com> Message-Id: <20210729132818.4091769-13-qperret@google.com> Mime-Version: 1.0 References: <20210729132818.4091769-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 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, 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 | 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..ae355bfd8c01 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 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