Received: by 2002:a05:6a10:c7c6:0:0:0:0 with SMTP id h6csp2171939pxy; Mon, 2 Aug 2021 22:32:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTGAVcrM3DGNLnzZW5sB7wOfIvvRGOAI9P6nIK3U0FtQWup83PkB9cQP+olVO0CnKx+cvX X-Received: by 2002:a6b:7114:: with SMTP id q20mr657455iog.71.1627968761866; Mon, 02 Aug 2021 22:32:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1627968761; cv=none; d=google.com; s=arc-20160816; b=sIfmV68gWgLCPW3p+S1WUxCWX+z8HI1nwZ8FVkqTaGtmO87vDdk6N2q8lzf/n7AEC1 wcbcQ44eqOK2UzywFQlF3tDuV9NCf4dndUY88HnQKJv8J7pK2bSeIlFZQfWDPyBAWt3/ 7jGSOPFXZBjAm0wgBcloXhBTT3vJYRPSjc7/xd6tcfYGECEfG+JDzmXIeHtbYAvo5uoG Bc1QVS2Bihe72Ya3FY0j41XvQVO9MtzRrwkxZTnkMBjRWhMguVMjxG2RSFZJA/qaINj7 OTftHG7uXIBzI0X9sfKhfOyCVOebGIhx2ZGwyrZgcjUF+nLyI+jGBYvZ9Fp0moY1IKoB QMuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Po/YZOILTmzrKkwPCgFv0W6S5rEcnTiI475aJx7OtDk=; b=cJ0VZ5VW8NBb4mpDGG9Betu5839LTVJITgGnd3cHcBdfi/e9GgWi+uf36AxEBctjbe gk4uB8BurgZWjVbKNDntk3b+m4gIf9LgYjQDkOvlSO62EG/2grDcMNaAl00YeEHO32yO 1Fj7ISJHRQks1epcM5hTgF+0ZwmvoJr2DwAk/jixBdqM/SwyNZp6FmuLXMsyTt3KPO/8 l/ysDkHsIw8JJwwIHYXl51uVp7pomtW2xRsqW0yX1wPZn2lpDTGjrkfYC7RJrGp0lM+4 VPxE2btRqGuMnIAQ3YmyKvDgGpRNmdg/6/KalpPPQlqLusklt76DnThAPJFMimupgDH1 oYNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=tspspKCz; 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 q8si16674927ilo.95.2021.08.02.22.32.28; Mon, 02 Aug 2021 22:32:41 -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=tspspKCz; 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 S233693AbhHCFbv (ORCPT + 99 others); Tue, 3 Aug 2021 01:31:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbhHCFbu (ORCPT ); Tue, 3 Aug 2021 01:31:50 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 675FDC061764 for ; Mon, 2 Aug 2021 22:31:40 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id 68-20020a9d0f4a0000b02904b1f1d7c5f4so19697328ott.9 for ; Mon, 02 Aug 2021 22:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Po/YZOILTmzrKkwPCgFv0W6S5rEcnTiI475aJx7OtDk=; b=tspspKCzxf3dmvM9PbDYEPm3AmQpSu50tc9b+llKKl7n1mT4jrbe+Z6JGQDcifMAF+ HQY90mmsaeiBqaBa0zJVodVm+2NmqPjcsViqcCVODxGkOF5ysu1zCjyeOvmQvutwqF2Q xyBGMpTCE/+qoBcJ9OZOU7EXqwbCN8VOrL8EA9myE9R0bcJs3uOPWRRr3HJNstqH1jHe M/awtkRnSp+XXF7yXRKRu0R6aVoLeZuxy4CgQzPVN95+XgmsjMVe7Rxalo7LE7ZsrA+P MBYrJ13XeNcKRFqBMNULhow1Bq3fV8f0w32XIuU7iAGaWWJwBU1MQat268IbtZ5tlcgV /L9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Po/YZOILTmzrKkwPCgFv0W6S5rEcnTiI475aJx7OtDk=; b=bxkL7itwEjK2qU1po8BMcrSDTKSXMGx63RIEskX+6q20C18UMpyuftCdp59kHISXk3 peDRBe8NwOnJ2nN5uwL54zDsGx56msQg0HeG71KfyaO6mZX5xLOltqdpKN8wNeeWyuKt eCE0E7NPGd/0lw3pma7prVjqVYCpopq0sYu5LUXzlKE3fkREzQKbKSlXLj5RMuz8CWc1 6wl2cFF6DC/5hzpn3/URCSDpwhxLPTXd/wRYcpAcCPWwjkCbPSsSGvQHkTl41rId9kte Vu6MWGA2jJqCohXkYAXdXJSz5IjX2j9Zq+Bc6WNm4EVVkw5b3NR0elH4bg2BBwwySLaZ FhHQ== X-Gm-Message-State: AOAM531Mj2LN+JyLaBHrGOwYW6gUHiCxto30b7oVsu16YsjlGMnlrdsg fAK1R5vAvOTUyBWugDKdk0WPbrPsBX0zVuQjs/YuvA== X-Received: by 2002:a05:6830:1455:: with SMTP id w21mr14380175otp.365.1627968699557; Mon, 02 Aug 2021 22:31:39 -0700 (PDT) MIME-Version: 1.0 References: <20210729132818.4091769-1-qperret@google.com> <20210729132818.4091769-20-qperret@google.com> In-Reply-To: <20210729132818.4091769-20-qperret@google.com> From: Fuad Tabba Date: Tue, 3 Aug 2021 07:31:03 +0200 Message-ID: Subject: Re: [PATCH v3 19/21] KVM: arm64: Refactor protected nVHE stage-1 locking To: Quentin Perret 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks, /fuad > int hyp_back_vmemmap(phys_addr_t phys, unsigned long size, phys_addr_t back) > { > unsigned long start, end; > -- > 2.32.0.432.gabb21c7263-goog >