Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp252936pxb; Wed, 6 Oct 2021 04:23:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoxW9U0anIhqz65TCsj/3IOhWMAQNEDQn00nLjvimICVmyFP5ajlhs4J5qtrw6kcHvMs6F X-Received: by 2002:a62:d11e:0:b0:446:d705:7175 with SMTP id z30-20020a62d11e000000b00446d7057175mr36376674pfg.74.1633519426919; Wed, 06 Oct 2021 04:23:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633519426; cv=none; d=google.com; s=arc-20160816; b=zKZhaxWUykVuPmbfZuVBDbH95tmAgRqdnxvKFDp4RdvG7BlZPu7N5+FBC3NZLdJKMB nQOLlDDCQBzDqWTfO/M9tpPAsIM4bzxh7RpuVbGOZT8kweC+rinzoXOygLUhYH0udXiG lQTPjNtnE7/Kn6mAtQ6Z+hTYuE5d+nmA48jfeAV2NtlBtQGkO0VM9agUym/W+r5VYYwx W6GFbEQJjGEofPNHBnxtpA4CbcsGqqwXGL9/t5cuyEQF0Hg8DkejXpe1QVNwr9MEnAD/ BAUxwRiS7xL+XZz9SvgtQb2D78uDjhIAbQuNo/TeASd0OcRw0RrW+wFJ0XNo3lZpzYy+ ATJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jWX5sU8D1+Ly4mm1f35q3sYrq7WIwVRiVd8SgiHRgOs=; b=vLQWstkLd7RIlIvLVjgr2oDnx5eTrh45nNwnoJyFCZ8pcnus2EyZEij8wePIK60k/J xmOs6onO4JhPp/dgMKjPNG935UNmMiAPUe0egLvyphGUFIQhMJoq43cdPY6NQPXrN641 o9KqVjfoKtdOnXdtRddKwr3ZJxfrtzqLQa1ahHReJxUMGkZD80BfRwrMqER8JtyIYvrv lQjmCfsDis9XefL2wEhsYwu0H9I4wgoyQRto1LhRMDZDCc61lKzp/KSAiCpJTnF/aFK5 RWpJlL9mpEQTM7qdUfq7yttR24TCXi+8W9BPS6t4UntlixWZU+uVDZlhuFL8hAa20dm4 RX7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JJozpYtc; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t4si25968126pgk.386.2021.10.06.04.23.32; Wed, 06 Oct 2021 04:23:46 -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=@redhat.com header.s=mimecast20190719 header.b=JJozpYtc; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238317AbhJFLYX (ORCPT + 99 others); Wed, 6 Oct 2021 07:24:23 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:45200 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238270AbhJFLYT (ORCPT ); Wed, 6 Oct 2021 07:24:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633519347; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=jWX5sU8D1+Ly4mm1f35q3sYrq7WIwVRiVd8SgiHRgOs=; b=JJozpYtc+lht4K+GR9dJN5iVdGpxBjbKn7W+xoieRxxQ8phKA4tZS2P8GEffRp5wvYpdCU SxZhMU+0m/ogneH6G953wzBOFfdZS4zdZbfYmzmV+0y3bbjtJiuxBF6cAZTYXDdA26zSeS 9AR6TvwvluTsM0a+vcwiYZgNpBinv8g= Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-473-dmP0G7BtNjeI9JEK8OJ-4g-1; Wed, 06 Oct 2021 07:22:26 -0400 X-MC-Unique: dmP0G7BtNjeI9JEK8OJ-4g-1 Received: by mail-ed1-f70.google.com with SMTP id c8-20020a50d648000000b003daa53c7518so2269110edj.21 for ; Wed, 06 Oct 2021 04:22:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=jWX5sU8D1+Ly4mm1f35q3sYrq7WIwVRiVd8SgiHRgOs=; b=s0kghtwZtqLES3GFrHoOTUHG1u8AkCCGcAgbdhx0EyUT5qL0VY1qL28vBakeAIjG0+ 5sk0GqCYRfIcQ82jN0pXs9jebzKbqiC/JDRoC8+zpfkP62wwDYbcZVmCet17d0DEYXMa ZTb2wavhkF0CdcEnFfNuOLI+RnUhasj4NIReEmMvuTNGiwFOYgpL0r6LioQ5RC8MgonY 6xQnSfA2sMRbybc1EsK/FZP3RGsEjlklMOGsl6MKJyyGqwXuTjDB0PfbFnhcsQ3JsPXo ax8kekBbuK6gPMaEFfvLMwQYVBTpV9pz51rFEkdkqc/T4v/72l4O77tHl7mKE8gSP6a7 kBwQ== X-Gm-Message-State: AOAM531KIyV/JXbDXidru/X7SihpEl8MGVBWEjiZgfSYlu4t5lifMnh1 euuA+G8SgRijXlLsII9HrFqV2Eo6koQcZzIJWFOnRnuM3MyXx+0q18+rYNpJYMZLfW0nq4e3bcl w0sAQyeclmZfoTSE+q6HMq6fW X-Received: by 2002:a17:906:4f82:: with SMTP id o2mr31730769eju.10.1633519344814; Wed, 06 Oct 2021 04:22:24 -0700 (PDT) X-Received: by 2002:a17:906:4f82:: with SMTP id o2mr31730745eju.10.1633519344572; Wed, 06 Oct 2021 04:22:24 -0700 (PDT) Received: from gator.home (cst2-174-28.cust.vodafone.cz. [31.30.174.28]) by smtp.gmail.com with ESMTPSA id u4sm1158745edj.33.2021.10.06.04.22.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Oct 2021 04:22:24 -0700 (PDT) Date: Wed, 6 Oct 2021 13:22:22 +0200 From: Andrew Jones To: Marc Zyngier Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, will@kernel.org, qperret@google.com, dbrazdil@google.com, Steven Price , Fuad Tabba , Srivatsa Vaddagiri , Shanker R Donthineni , James Morse , Suzuki K Poulose , Alexandru Elisei , kernel-team@android.com Subject: Re: [PATCH v2 03/16] KVM: arm64: Turn kvm_pgtable_stage2_set_owner into kvm_pgtable_stage2_annotate Message-ID: <20211006112222.ahfhtkhamdi3svm5@gator.home> References: <20211004174849.2831548-1-maz@kernel.org> <20211004174849.2831548-4-maz@kernel.org> <20211006110211.y6kzmjlzgardmwif@gator.home> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211006110211.y6kzmjlzgardmwif@gator.home> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 06, 2021 at 01:02:11PM +0200, Andrew Jones wrote: > On Mon, Oct 04, 2021 at 06:48:36PM +0100, Marc Zyngier wrote: > > kvm_pgtable_stage2_set_owner() could be generalised into a way > > to store up to 63 bits in the page tables, as long as we don't > > set bit 0. > > > > Let's just do that. > > > > Signed-off-by: Marc Zyngier > > --- > > arch/arm64/include/asm/kvm_pgtable.h | 12 ++++++----- > > arch/arm64/kvm/hyp/include/nvhe/mem_protect.h | 2 +- > > arch/arm64/kvm/hyp/nvhe/mem_protect.c | 11 ++++------ > > arch/arm64/kvm/hyp/nvhe/setup.c | 10 +++++++++- > > arch/arm64/kvm/hyp/pgtable.c | 20 ++++++------------- > > 5 files changed, 27 insertions(+), 28 deletions(-) > > > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > > index 027783829584..d4d3ae0b5edb 100644 > > --- a/arch/arm64/include/asm/kvm_pgtable.h > > +++ b/arch/arm64/include/asm/kvm_pgtable.h > > @@ -329,14 +329,16 @@ int kvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, > > void *mc); > > > > /** > > - * kvm_pgtable_stage2_set_owner() - Unmap and annotate pages in the IPA space to > > - * track ownership. > > + * kvm_pgtable_stage2_annotate() - Unmap and annotate pages in the IPA space > > + * to track ownership (and more). > > * @pgt: Page-table structure initialised by kvm_pgtable_stage2_init*(). > > * @addr: Base intermediate physical address to annotate. > > * @size: Size of the annotated range. > > * @mc: Cache of pre-allocated and zeroed memory from which to allocate > > * page-table pages. > > - * @owner_id: Unique identifier for the owner of the page. > > + * @annotation: A 63 bit value that will be stored in the page tables. > > + * @annotation[0] must be 0, and @annotation[63:1] is stored > > + * in the page tables. > > * > > * By default, all page-tables are owned by identifier 0. This function can be > > * used to mark portions of the IPA space as owned by other entities. When a > > @@ -345,8 +347,8 @@ int kvm_pgtable_stage2_map(struct kvm_pgtable *pgt, u64 addr, u64 size, > > * > > * Return: 0 on success, negative error code on failure. > > */ > > -int kvm_pgtable_stage2_set_owner(struct kvm_pgtable *pgt, u64 addr, u64 size, > > - void *mc, u8 owner_id); > > +int kvm_pgtable_stage2_annotate(struct kvm_pgtable *pgt, u64 addr, u64 size, > > + void *mc, kvm_pte_t annotation); > > > > /** > > * kvm_pgtable_stage2_unmap() - Remove a mapping from a guest stage-2 page-table. > > diff --git a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > > index b58c910babaf..9d2ca173ea9a 100644 > > --- a/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > > +++ b/arch/arm64/kvm/hyp/include/nvhe/mem_protect.h > > @@ -53,7 +53,7 @@ int __pkvm_host_share_hyp(u64 pfn); > > > > bool addr_is_memory(phys_addr_t phys); > > int host_stage2_idmap_locked(phys_addr_t addr, u64 size, enum kvm_pgtable_prot prot); > > -int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id); > > +int host_stage2_annotate_locked(phys_addr_t addr, u64 size, kvm_pte_t owner_id); > > int kvm_host_prepare_stage2(void *pgt_pool_base); > > void handle_host_mem_abort(struct kvm_cpu_context *host_ctxt); > > > > diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > > index bacd493a4eac..8cd0c3bdb911 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c > > +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c > > @@ -286,17 +286,14 @@ static int host_stage2_adjust_range(u64 addr, struct kvm_mem_range *range) > > int host_stage2_idmap_locked(phys_addr_t addr, u64 size, > > enum kvm_pgtable_prot prot) > > { > > - hyp_assert_lock_held(&host_kvm.lock); > > - > > return host_stage2_try(__host_stage2_idmap, addr, addr + size, prot); > > } > > > > -int host_stage2_set_owner_locked(phys_addr_t addr, u64 size, u8 owner_id) > > +int host_stage2_annotate_locked(phys_addr_t addr, u64 size, > > + kvm_pte_t annotation) > > { > > - hyp_assert_lock_held(&host_kvm.lock); > > Hi Marc, > > Why are the lock asserts getting dropped? Ah, I see. host_stage2_try already has the same assert. Reviewed-by: Andrew Jones Thanks, drew