Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp4412942pxv; Tue, 20 Jul 2021 03:14:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyI64w9I6ILIe9w9Y1ny/H/bZFTUOva9c+md63B+vLd+YbrKw/qT4KJEE3bQDeSZkLGMKWI X-Received: by 2002:a5d:9585:: with SMTP id a5mr23199824ioo.28.1626776083620; Tue, 20 Jul 2021 03:14:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626776083; cv=none; d=google.com; s=arc-20160816; b=FIPPAJZnO8pjUWTboZzyDWxBYxJLbvU6wYYitF4kJ8BYO6i6YHmT4vOqKIshBj0bR/ PQp1jfKIvJmTmOv+gLRtZyKJsVnJvamLipsBrKDlebRUYNl/89U/5uJfV/ERgRBcaBjE ytfoWvXUd7yzapLvdNUa8PLWAX6Rf/HxyPkfRojY4mdxi/bH7W0szIC6kM8CW26IIMX8 cw5syJrrxw39ywGfDwUfb2gYO1DDhj2FYZQxQLLOuQ3Sn52eTHRaGU4TQB9Q6cuIOYWO C5xHWTrJ5BfP+QsOf32fQdx7Twe9z0V9XIESvq1PSp0BTQnrr5UoN5UMIRRkB/IChi3l UP5A== 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=mQQzaEU+NRfrfvk/w9pJ8xoONzx5Sp2Z9bJ6y5svj+k=; b=JQobsAbcCQPaFkHfM3sq4PWmVlqZn97Z8IqNQRLpMGZc7MVRhdCtDmKqnI+Kri1iLv a+rpfQ0Ae1nVovNYL0wr7BR+etqCEU6kPuAstaBKRU8Sk9md6uJ/wXGe0Gdd4koeULY6 RFGAhMQ9bKaEGVJHwar/9tg/qjrpJZndYKsLJyfQDCVJW6+m2YiFUfvns92GWUBDjwNW eFkexOcfCkt/ItLsm6z4xPUf7EzkcrLi7CzodQ3Bn1GY6xWzk0G0CCPxbusVHH13hdrl 3GkMTaFiYGyXUWO9I3VTHalVJhWtdsud4gujcsL7gGo3vS9qcXFOE6phlcSZKZvBgwAn Pqvg== 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 x10si511638ilu.80.2021.07.20.03.14.32; Tue, 20 Jul 2021 03:14:43 -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 S235984AbhGTJdE (ORCPT + 99 others); Tue, 20 Jul 2021 05:33:04 -0400 Received: from mail.kernel.org ([198.145.29.99]:56906 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233914AbhGTJc7 (ORCPT ); Tue, 20 Jul 2021 05:32:59 -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 8B0D0610C7; Tue, 20 Jul 2021 10:13:33 +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 1m5mkl-00EU1u-Gx; Tue, 20 Jul 2021 11:13:31 +0100 Date: Tue, 20 Jul 2021 11:13:31 +0100 Message-ID: <8735s99ttg.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: References: <20210719104735.3681732-1-qperret@google.com> <20210719104735.3681732-9-qperret@google.com> <87fswajre1.wl-maz@kernel.org> 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 16:49:13 +0100, Quentin Perret wrote: > > On Monday 19 Jul 2021 at 15:43:34 (+0100), Marc Zyngier wrote: > > 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. > > Works for me -- I just wanted to make sure we don't have users in > different places that use the same bits without knowing, but no strong > opinions, so happy to change. > > > > }; > > > > > > #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? > > Sure. > > > > +{ > > > + 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()? > > It should leave SW bits untouched, and it really felt like a path were > we want to change permissions and nothing else. What did you have in > mind? It isn't clear to me that it would not (cannot?) be used to change other bits, given that it takes an arbitrary 'prot' set. If there is such an intended restriction, we definitely should document it. M. -- Without deviation from the norm, progress is not possible.