Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2322601pxy; Tue, 3 Aug 2021 03:38:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCLJSMhPEUTBQJpp99oShpXg7vFS7wsUzS3IBAcyHWZok0xxTI9UWwJ15XwiR95li2Tm2E X-Received: by 2002:a05:6402:4412:: with SMTP id y18mr24451472eda.1.1627987133411; Tue, 03 Aug 2021 03:38:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627987133; cv=none; d=google.com; s=arc-20160816; b=xTLIGidMbkKGgbUsNyXAoM9YGHaanwTzTx2BU1LJ36CgacZY/bv6KwLSwZjlXypNbt BBax9fSnXFiP+7z92zDtIYwPScye66pB5DkKQlwfzGGluk/bWkTlqoBsqAq8ZbsJv2Vp 1dOURepe5X9CXWHEGXl+216s0AwPilpSoBsV5pu3v7AAWEppJ91Ri5TbY/XISfsxOWPN ujCFkpEV0zzLgtJrsM/i0mLf+PzBw2hcpXx9ccLjafq07D7MvxkAbntL+ZHVVOe2qZ/u pmvGwlwwz0CLq80fAGoycmGX981PylPan3CUCtBEoVhg7C4QAX/ealUPleylVwDT3oNP ebNg== 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=OfCoiih4+kjHguXqFPDXzH6cgIOlyrxD4TS+l5ysvFk=; b=mAEvFIOqcMyC9vkzTGsL0TBAZbzQXuGIq04NK9RcAFzpUAbGNjcyRtOG8IO/rsTqjl m+cn5yguwK7645jgKdnh4TjpB7xXJO1RTg65yHpFsx8bUKJ/yqicmq1AszDySHQoRLJ/ Lz0JXDJM45Lmu07t8Rjkxzfmw1Do+5F55W24eoyql18/rRYyNU+pUHv89RW5mMXZ3Nm8 8FirUsPBloMGtZGwSN/De4PlpVM3IgE6WW3gcfj/vK/JKdA1gxLbMv9wVdA/wOjcxrTV gVIENA3pJ0SHIfFV1Z+Z8WwNCdhGWHj587OIijb6/gDL/FxdUs/QfjrBptwF+XpfTNcI og8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=oK1JvaEl; 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 nd36si2246905ejc.253.2021.08.03.03.38.29; Tue, 03 Aug 2021 03:38:53 -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=oK1JvaEl; 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 S234998AbhHCKhW (ORCPT + 99 others); Tue, 3 Aug 2021 06:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235241AbhHCKhV (ORCPT ); Tue, 3 Aug 2021 06:37:21 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 482E5C06175F for ; Tue, 3 Aug 2021 03:37:10 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id h13so11308232wrp.1 for ; Tue, 03 Aug 2021 03:37:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=OfCoiih4+kjHguXqFPDXzH6cgIOlyrxD4TS+l5ysvFk=; b=oK1JvaEldDcXbbl7XIpC2KQbuUB307XsvhZpKIw98fEC9HM3SeC2pQ3JMF0HUSBICg 9R/Uc4FraONJ/tY44FUQcM4ppaXjUZ2Dwth2OZi/Lblhoe/T/Y5IZ3oR36WW7xqIMmc+ vTKjnl6ElslWknLnGL9Nr4Of+7PNlOzZ6SSJU2GiCfw6Gp35Ul7EyZiTi+5uoKIM5pGs V3+Y/4Po+Odcy3c7s5D3G+nOrmVDjkqAcUuM+ofq7D9NTaRJQzxBEwip3+hlRMlUVTbn 4x+TtKjws6Vpe6vw43bShnCMM7pTkw2Xsx7OkdIeGptyb/YT/1jXxJpnISXK77hONqn0 eaLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=OfCoiih4+kjHguXqFPDXzH6cgIOlyrxD4TS+l5ysvFk=; b=l5B8Fk2qvjEoU/2yXmMu46r2BJFx9qeRPIWI++NGliOQANqqhy0WLNOn/OwKLhF1hf gZtRWx/6JTzwDYwl89dHdv0OpDIUbq82uthOb7WknJDjWrbKcrdYjl1/PlXfQ5d32pOv 0NTKFvsUUXjDRcPoQDPR5SQy9K8bGaEmGCjDl2JjPluVpUbZXbzB8l9xToX/qBCAYV1r b0Fifbw+grY2OHl90xAioY1w49GszB/rDXmtw3E+OLDAiTR3OrvRh9t80LyHJhdDyB04 tqgVxTkXYwc705ArN7im3CfJSjVirA9hkCQEsc8Fd9bq91ir9Z3Ak7FhVvpv4JcCBrDm 7QEg== X-Gm-Message-State: AOAM530aIdONam1PjJLm7m25biYCZp47o39/4CSF6IUe1cHzhMDjSxZe MVt1bzdNKCZRi4M23xUaLwc05g== X-Received: by 2002:a5d:6692:: with SMTP id l18mr21756760wru.85.1627987028707; Tue, 03 Aug 2021 03:37:08 -0700 (PDT) Received: from google.com ([2a00:79e0:d:210:754:7d1b:7303:129a]) by smtp.gmail.com with ESMTPSA id i7sm14652599wre.64.2021.08.03.03.37.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Aug 2021 03:37:08 -0700 (PDT) Date: Tue, 3 Aug 2021 11:37:05 +0100 From: Quentin Perret To: Fuad Tabba Cc: maz@kernel.org, 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, dbrazdil@google.com, kernel-team@android.com Subject: Re: [PATCH v3 19/21] KVM: arm64: Refactor protected nVHE stage-1 locking Message-ID: References: <20210729132818.4091769-1-qperret@google.com> <20210729132818.4091769-20-qperret@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hey Fuad, On Tuesday 03 Aug 2021 at 07:31:03 (+0200), Fuad Tabba wrote: > Hi Quentin, > > On Thu, Jul 29, 2021 at 3:29 PM Quentin Perret wrote: > > > > Refactor the hypervisor stage-1 locking in nVHE protected mode to expose > > a new pkvm_create_mappings_locked() function. This will be used in later > > patches to allow walking and changing the hypervisor stage-1 without > > releasing the lock. > > > > Signed-off-by: Quentin Perret > > --- > > arch/arm64/kvm/hyp/include/nvhe/mm.h | 1 + > > arch/arm64/kvm/hyp/nvhe/mm.c | 18 ++++++++++++++++-- > > 2 files changed, 17 insertions(+), 2 deletions(-) > > > > diff --git a/arch/arm64/kvm/hyp/include/nvhe/mm.h b/arch/arm64/kvm/hyp/include/nvhe/mm.h > > index 8ec3a5a7744b..c76d7136ed9b 100644 > > --- a/arch/arm64/kvm/hyp/include/nvhe/mm.h > > +++ b/arch/arm64/kvm/hyp/include/nvhe/mm.h > > @@ -23,6 +23,7 @@ int hyp_map_vectors(void); > > int hyp_back_vmemmap(phys_addr_t phys, unsigned long size, phys_addr_t back); > > int pkvm_cpu_set_vector(enum arm64_hyp_spectre_vector slot); > > int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot); > > +int pkvm_create_mappings_locked(void *from, void *to, enum kvm_pgtable_prot prot); > > int __pkvm_create_mappings(unsigned long start, unsigned long size, > > unsigned long phys, enum kvm_pgtable_prot prot); > > unsigned long __pkvm_create_private_mapping(phys_addr_t phys, size_t size, > > diff --git a/arch/arm64/kvm/hyp/nvhe/mm.c b/arch/arm64/kvm/hyp/nvhe/mm.c > > index a8efdf0f9003..6fbe8e8030f6 100644 > > --- a/arch/arm64/kvm/hyp/nvhe/mm.c > > +++ b/arch/arm64/kvm/hyp/nvhe/mm.c > > @@ -67,13 +67,15 @@ unsigned long __pkvm_create_private_mapping(phys_addr_t phys, size_t size, > > return addr; > > } > > > > -int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) > > +int pkvm_create_mappings_locked(void *from, void *to, enum kvm_pgtable_prot prot) > > { > > unsigned long start = (unsigned long)from; > > unsigned long end = (unsigned long)to; > > unsigned long virt_addr; > > phys_addr_t phys; > > > > + hyp_assert_lock_held(&pkvm_pgd_lock); > > + > > start = start & PAGE_MASK; > > end = PAGE_ALIGN(end); > > > > @@ -81,7 +83,8 @@ int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) > > int err; > > > > phys = hyp_virt_to_phys((void *)virt_addr); > > - err = __pkvm_create_mappings(virt_addr, PAGE_SIZE, phys, prot); > > + err = kvm_pgtable_hyp_map(&pkvm_pgtable, virt_addr, PAGE_SIZE, > > + phys, prot); > > if (err) > > return err; > > } > > @@ -89,6 +92,17 @@ int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) > > return 0; > > } > > > > +int pkvm_create_mappings(void *from, void *to, enum kvm_pgtable_prot prot) > > +{ > > + int ret; > > + > > + hyp_spin_lock(&pkvm_pgd_lock); > > + ret = pkvm_create_mappings_locked(from, to, prot); > > + hyp_spin_unlock(&pkvm_pgd_lock); > > + > > + return ret; > > +} > > + > > I'm wondering whether this patch should also refactor > __pkvm_create_mappings. It doesn't quite do the exact same thing and > has different parameters. Sorry, not sure I'm understanding your suggestion here. What do you think should be done to __pkvm_create_mappings? Cheers, Quentin