Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3743341pxv; Mon, 19 Jul 2021 07:44:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymlrJXcL7UFFnlgPV9+RBezGFDsxbRMjB3fWrBDbGC8LyycTqF97UlsafoenEdBRsv74eb X-Received: by 2002:a05:6402:1615:: with SMTP id f21mr34755346edv.35.1626705889737; Mon, 19 Jul 2021 07:44:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626705889; cv=none; d=google.com; s=arc-20160816; b=ZW4ATNoC8N4G6TZRB2hSI9aMfyUGq4ELjzu5I7qNqjfvxybCijAk+zhQ/NPrhvnmMD JnsbJnBxi7BTcJqpUAO84O291+fV5nwB7HMyHAQ7xvjK1v9Mjai7qS2IcyoArhnLTde4 uBEUMgVBIbnhOv6wfBMwVKNBYzc+GFIx502BRXHLK1ka+KGLiPvkBJYtW6smTA01okND OVVD1wi3pfMQvHrA+HlEv2Jia2pM6SQLl2qKPwdlUGiqVl9M7Zp/SdJlkiJzF6CNiNYt Jo+93HtV1dFgb/cw4QYssTmOix2L0Huq1fev0inDcWmI81FjZ0U64/uxcBi1e2edankl BMrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent:references:in-reply-to :subject:cc:to:from:message-id:date; bh=9Lul93nnUAJa+RV7TDFiATds9PwQYuq7ZDaAdWiTfgE=; b=mwZaIXxRktGcFeARShb3n9eXZ1IMnMZVmZMK3hgnwfJ8ZfaRrF73cbSqgW8Jyu0KWj XsJz7myv3GcrCbFa0W1AlIgEuNaXkXQ7WJSyasfuQk8c0HlO8/65McGYEZiGgKWtJDsx 7El0X0ITWbe0HZgj+0l8TE1xAbKCQ/i3q2cO7dlwwhBl0NgsiVF2svFx47v+KTjEeYwJ HARGcLYWTWpXASARxFpPW05FtWFV2EXQKexNItyiYIMH/llFeqzpm+s+k0D+86hf4aRU SJcjECCkkIBCJLyG+LKzQTdRG1sIB81nVD2fBLq3/ZK5D4w9TbTmMf9O4Eksl6ojAf9D Tipw== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si22150251ejx.722.2021.07.19.07.44.27; Mon, 19 Jul 2021 07:44:49 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241059AbhGSOC5 (ORCPT + 99 others); Mon, 19 Jul 2021 10:02:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:38562 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232531AbhGSOC4 (ORCPT ); Mon, 19 Jul 2021 10:02:56 -0400 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 8948661003; Mon, 19 Jul 2021 14:43:36 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m5UUY-00EEFY-MJ; Mon, 19 Jul 2021 15:43:34 +0100 Date: Mon, 19 Jul 2021 15:43:34 +0100 Message-ID: <87fswajre1.wl-maz@kernel.org> From: Marc Zyngier To: Quentin Perret Cc: james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, 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 Subject: Re: [PATCH 08/14] KVM: arm64: Add support for tagging shared pages in page-table In-Reply-To: <20210719104735.3681732-9-qperret@google.com> References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-9-qperret@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: qperret@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, 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 X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 19 Jul 2021 11:47:29 +0100, Quentin Perret wrote: > > The hypervisor will soon be in charge of tracking ownership of all > memory pages in the system. The current page-tracking infrastructure at > EL2 only allows binary states: a page is either owned or not by an > entity. But a number of use-cases will require more complex states for > pages that are shared between two entities (host, hypervisor, or guests). > > In preparation for supporting these use-cases, introduce in the KVM > page-table library some infrastructure allowing to tag shared pages > using ignored bits (a.k.a. software bits) in PTEs. > > Signed-off-by: Quentin Perret > --- > arch/arm64/include/asm/kvm_pgtable.h | 5 +++++ > arch/arm64/kvm/hyp/pgtable.c | 25 +++++++++++++++++++++++++ > 2 files changed, 30 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > index dd72653314c7..f6d3d5c8910d 100644 > --- a/arch/arm64/include/asm/kvm_pgtable.h > +++ b/arch/arm64/include/asm/kvm_pgtable.h > @@ -81,6 +81,8 @@ enum kvm_pgtable_stage2_flags { > * @KVM_PGTABLE_PROT_W: Write permission. > * @KVM_PGTABLE_PROT_R: Read permission. > * @KVM_PGTABLE_PROT_DEVICE: Device attributes. > + * @KVM_PGTABLE_STATE_SHARED: Page shared with another entity. > + * @KVM_PGTABLE_STATE_BORROWED: Page borrowed from another entity. > */ > enum kvm_pgtable_prot { > KVM_PGTABLE_PROT_X = BIT(0), > @@ -88,6 +90,9 @@ enum kvm_pgtable_prot { > KVM_PGTABLE_PROT_R = BIT(2), > > KVM_PGTABLE_PROT_DEVICE = BIT(3), > + > + KVM_PGTABLE_STATE_SHARED = BIT(4), > + KVM_PGTABLE_STATE_BORROWED = BIT(5), I'd rather have some indirection here, as we have other potential users for the SW bits outside of pKVM (see the NV series, which uses some of these SW bits as the backend for TTL-based TLB invalidation). Can we instead only describe the SW bit states in this enum, and let the users map the semantic they require onto that state? See [1] for what I carry in the NV branch. > }; > > #define KVM_PGTABLE_PROT_RW (KVM_PGTABLE_PROT_R | KVM_PGTABLE_PROT_W) > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index 5bdbe7a31551..51598b79dafc 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -211,6 +211,29 @@ static kvm_pte_t kvm_init_invalid_leaf_owner(u8 owner_id) > return FIELD_PREP(KVM_INVALID_PTE_OWNER_MASK, owner_id); > } > > +static kvm_pte_t pte_ignored_bit_prot(enum kvm_pgtable_prot prot) Can we call these sw rather than ignored? > +{ > + kvm_pte_t ignored_bits = 0; > + > + /* > + * Ignored bits 0 and 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). > + */ > + if (prot & KVM_PGTABLE_STATE_SHARED) { > + if (prot & KVM_PGTABLE_STATE_BORROWED) > + ignored_bits |= BIT(1); > + else > + ignored_bits |= BIT(0); > + } > + > + return FIELD_PREP(KVM_PTE_LEAF_ATTR_IGNORED, ignored_bits); > +} > + > 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) > @@ -357,6 +380,7 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep) > attr |= FIELD_PREP(KVM_PTE_LEAF_ATTR_LO_S1_AP, ap); > attr |= FIELD_PREP(KVM_PTE_LEAF_ATTR_LO_S1_SH, sh); > attr |= KVM_PTE_LEAF_ATTR_LO_S1_AF; > + attr |= pte_ignored_bit_prot(prot); > *ptep = attr; > > return 0; > @@ -558,6 +582,7 @@ static int stage2_set_prot_attr(struct kvm_pgtable *pgt, enum kvm_pgtable_prot p > > attr |= FIELD_PREP(KVM_PTE_LEAF_ATTR_LO_S2_SH, sh); > attr |= KVM_PTE_LEAF_ATTR_LO_S2_AF; > + attr |= pte_ignored_bit_prot(prot); > *ptep = attr; > > return 0; How about kvm_pgtable_stage2_relax_perms()? Thanks, M. [1] https://git.kernel.org/pub/scm/linux/kernel/git/maz/arm-platforms.git/commit/?h=kvm-arm64/nv-5.13&id=5dea6d82de76cfcda59818ec2532fc34c615db39 -- Without deviation from the norm, progress is not possible.