Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp397276pxb; Tue, 19 Oct 2021 05:16:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxapiYHwvPF5WKhvVSBWI2cuELnQjjfA7Ay5rPa+Ev/DDKG4P9t/0L6XiIdVuToCuq+hQBe X-Received: by 2002:aa7:d14b:: with SMTP id r11mr54431109edo.173.1634645813525; Tue, 19 Oct 2021 05:16:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634645813; cv=none; d=google.com; s=arc-20160816; b=g8HsJitIdc2uBKj1qu9XvCg1w2x6ySpRfAqRx/RX96y2IHpD/Cm+9ca5ghe9L1U5X+ gRRLzniYkB7tfD88sucd3ie9DoqyLgiot6itEcT7+3TSEaaWaskX5+WK2GOSRA254mM2 wzFRPNUCULvyiWzELeCYtwBzCfkrjtsHpjS77K8FpbSD5z303eR2iNVo53xpI2yCYULT eBHUs1hFv+hvZlC0K8UqSJm187vn8ZCrXs7uhnaAUQlKwYFc8ljg8plydanVe5rmOj8b vw/GkyzgDA5mPQdoD27JR0ejjrdKAr/PpW9w5dHW09PL+tDKV3+Ep5ZCFzzKh2FV95Qr j2fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:references:mime-version :message-id:in-reply-to:date:dkim-signature; bh=XSGm2ZIKVrWUlcjyigReTRCR+F+26tmq3jrTuKF0cGY=; b=wEWko6cJGjeuhKoHQXF/s1nK5qceEhYYhdhHxHF9Cyd5BpCZTzqjtpEkKDZsQHtnMB Z8dWQnVzZEnhG4IOKspQw1h+g1EjhEVdk4INCUMC5pRXavqd3POB2VQG4BsOTaPPFb+O JUwgbSc5dtvoxEY7bESANEsFTX7ZkAZgzVQ6NOCWaZyO1/p/x8T9iQVx9MFhMgaJ10EE Y9cjQH0+4WJ1A+I+mjZnbmy+77pAct1G4eI08fixIUkulVhbMGO858uCDB2Uqj2dB7p/ dQgNSOnodxKazk2yHxDkV46QUzVU3yLnB8+lvBZKM9iYy5Z7pEtbobKuFYp+/i6H7aNG 4U4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="Ff2j/4N+"; 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 z13si28992818edc.73.2021.10.19.05.16.16; Tue, 19 Oct 2021 05:16: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=20210112 header.b="Ff2j/4N+"; 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 S235613AbhJSMPz (ORCPT + 99 others); Tue, 19 Oct 2021 08:15:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235588AbhJSMPq (ORCPT ); Tue, 19 Oct 2021 08:15:46 -0400 Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AE86C061765 for ; Tue, 19 Oct 2021 05:13:31 -0700 (PDT) Received: by mail-wr1-x44a.google.com with SMTP id p12-20020adfc38c000000b00160d6a7e293so10046836wrf.18 for ; Tue, 19 Oct 2021 05:13:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=XSGm2ZIKVrWUlcjyigReTRCR+F+26tmq3jrTuKF0cGY=; b=Ff2j/4N+CqKMpFaKt5pCbLJb0KMSeXSN5oHh9p1pg7HOlQUt4WVieG3ZBh7ENNwFm5 viyVQrMK1sbcJirVOPfonTx/8M/aJhkeJ5B0u39TrugRP37ewl3yR7JqNBkgGs5haXuK 2fi9U7qJQGDInMSacShFQe6bjTZGdOvZEJjC2u9S3JYEC9A/zFpkeAbhlKyXkFOd6lwC oL4KmJI4uy8trhkrcZEQPwkbiQ5Bl3dvWof9sI+QQEALuNIQmcBzTtZ0TfprSuIPENHy ufCkQwqZGkNRKzejuz/j5PitlWgZX9pmE79oY8xDJrop9UJlUpRgizFQwE0bT83ExOBQ UJSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=XSGm2ZIKVrWUlcjyigReTRCR+F+26tmq3jrTuKF0cGY=; b=finPXQoiQPVvE7NDOQ5KIdHoXY0u99TuamzXySttmyQ6EcQ4UyLeu4UZGiRh53fDCY Gh9zWSbyZ46nKfQHPQuJbI8HTzp/KAt/amSsXNbQHde3xnOM3iQfU+Xpvf4S+N2qeIr8 i6KhdvBAyUuNAjcOGL8fdCYLIc1NKQmm9Y3QowhA6BIbRNPY/RDAmF+SRb7W2XfJj/ri 34VpHn8LfebKsPURAqXdBmOMpDiDfrdCBcj+2ZpwJjj/NdkdIXHKmzKIa13H+VXE3lsA fUP8qjOYWwgMG4hWNeqgWy6uoldh9+6+CEWMCdUuOSeNGKjOLZuEhyYRCb7nhLRNSCcq S9aw== X-Gm-Message-State: AOAM530oaVdSOUwJPgcz8cYBQdWmrVgPoel06t5BI8y7M/vIO8IebxZa o4uZE8jWMFiSRU20N2ye2xa/frAHZljo X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:59ca:401f:83a8:de6d]) (user=qperret job=sendgmr) by 2002:adf:b302:: with SMTP id j2mr44597972wrd.285.1634645610149; Tue, 19 Oct 2021 05:13:30 -0700 (PDT) Date: Tue, 19 Oct 2021 13:12:59 +0100 In-Reply-To: <20211019121304.2732332-1-qperret@google.com> Message-Id: <20211019121304.2732332-11-qperret@google.com> Mime-Version: 1.0 References: <20211019121304.2732332-1-qperret@google.com> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog Subject: [PATCH v2 10/15] KVM: arm64: Introduce wrappers for host and hyp spin lock accessors From: Quentin Perret To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Fuad Tabba , David Brazdil , Andrew Walbran Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com, qperret@google.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Will Deacon In preparation for adding additional locked sections for manipulating page-tables at EL2, introduce some simple wrappers around the host and hypervisor locks so that it's a bit easier to read and bit more difficult to take the wrong lock (or even take them in the wrong order). Signed-off-by: Will Deacon Signed-off-by: Quentin Perret --- arch/arm64/kvm/hyp/nvhe/mem_protect.c | 32 ++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/mem_protect.c b/arch/arm64/kvm/hyp/nvhe/mem_protect.c index 1f0fb0780622..c111e0fcfa0a 100644 --- a/arch/arm64/kvm/hyp/nvhe/mem_protect.c +++ b/arch/arm64/kvm/hyp/nvhe/mem_protect.c @@ -27,6 +27,26 @@ static struct hyp_pool host_s2_pool; const u8 pkvm_hyp_id = 1; +static void host_lock_component(void) +{ + hyp_spin_lock(&host_kvm.lock); +} + +static void host_unlock_component(void) +{ + hyp_spin_unlock(&host_kvm.lock); +} + +static void hyp_lock_component(void) +{ + hyp_spin_lock(&pkvm_pgd_lock); +} + +static void hyp_unlock_component(void) +{ + hyp_spin_unlock(&pkvm_pgd_lock); +} + static void *host_s2_zalloc_pages_exact(size_t size) { return hyp_alloc_pages(&host_s2_pool, get_order(size)); @@ -327,14 +347,14 @@ static int host_stage2_idmap(u64 addr) prot = is_memory ? PKVM_HOST_MEM_PROT : PKVM_HOST_MMIO_PROT; - hyp_spin_lock(&host_kvm.lock); + host_lock_component(); ret = host_stage2_adjust_range(addr, &range); if (ret) goto unlock; ret = host_stage2_idmap_locked(range.start, range.end - range.start, prot); unlock: - hyp_spin_unlock(&host_kvm.lock); + host_unlock_component(); return ret; } @@ -358,8 +378,8 @@ int __pkvm_host_share_hyp(u64 pfn) if (!addr_is_memory(addr)) return -EINVAL; - hyp_spin_lock(&host_kvm.lock); - hyp_spin_lock(&pkvm_pgd_lock); + host_lock_component(); + hyp_lock_component(); ret = kvm_pgtable_get_leaf(&host_kvm.pgt, addr, &pte, NULL); if (ret) @@ -421,8 +441,8 @@ int __pkvm_host_share_hyp(u64 pfn) BUG_ON(ret); unlock: - hyp_spin_unlock(&pkvm_pgd_lock); - hyp_spin_unlock(&host_kvm.lock); + hyp_unlock_component(); + host_unlock_component(); return ret; } -- 2.33.0.1079.g6e70778dc9-goog