From patchwork Wed Dec 1 17:04:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12694357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3D4DEC433EF for ; Wed, 1 Dec 2021 17:09:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Gi+RS31tgR+uVr6egEVZ1GPdiwBZ/X6dJdnEvDWCta4=; b=S5ton3rNacggEN/5FUvlrU4zpt RXroeFpG0cqPUPXZd2/SGIB+CYM7FBzYKFyAYLFBCmn43cP3K4j+5WNrILi4duyr+UQn3Kf9PEqNc 2TMJbErsPf80aTGu1k7V17PEhjBAqwIV6MGP2LG+TzCnvXXIpGBkb1hvliuWjXUwRJuu5ctRISJdG rR6ZYv57JTftnkm/ypnj5yLGpoeVavcKqk+b6EmhXwzraP+qwsTResCsugWAeVNU47i2hQrPlMVyd QmM6aLbmt3SZ6BJldVhR1OL0WdX6WiONt/VsDXa3W2PGD2Q4yjkKTrMjfeJd4AUyKB3o6wVEtUYPN PP3IXd2A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msT5R-009TeM-A8; Wed, 01 Dec 2021 17:08:05 +0000 Received: from mail-wr1-x44a.google.com ([2a00:1450:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1msT2N-009Rzk-Jt for linux-arm-kernel@lists.infradead.org; Wed, 01 Dec 2021 17:04:57 +0000 Received: by mail-wr1-x44a.google.com with SMTP id r2-20020adfe682000000b00198af042b0dso4462675wrm.23 for ; Wed, 01 Dec 2021 09:04:54 -0800 (PST) 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=T0JsrzG68YfPigMGVPlPrd/xCSmb5pbfUw0MQLeIq18=; b=FxwXE/GBzpALB+WDGk4xxS/qk7AEHYIAQOFqBsax91XFh54Oe4XTkZKSH5mjhhiGwi xojuzI07IO1NX0heyd2/dn4DPfxq0MBzpigfJwCCo9EWFe/7k5cjD6K87Hr1bnzMr75n LPvlTZ5UVckhBdhWY1tA5gp6BooYMA6vk6UqpvQCQKxmxXijzAAUxOLQHmq3W/UT5K76 LLOzTHeRcv7HG31p0iL095jbrbR4CWaw0qd/Lm3WvIAX+mRlmQSBbLi4bERT3mmAXGm9 giXC8vRUXTgmyMn6BJyiPcxZQDAjsrAMk92/xCu0oed2MKOEUxmlhKYTnIEcRcGVQi/j d5Rg== 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=T0JsrzG68YfPigMGVPlPrd/xCSmb5pbfUw0MQLeIq18=; b=6uUkiWtjs/5pmkCKAzQS7pB70nnFWlimMgd3pUA05y6yO4bUp5wqUOVS1ZfNfkuClP rBzDgiO5X1syrjxnltvRMZDD7I++lbsT9qiFTi/3sCwyPysFe9nN/us/qUdcptLOsGW4 EAPy39GZo57FOlheVymwCyBerF01HB5On+T0qMy7hTHqkgvYnZDJfcORu24y73iihWyL lHz36SqbkOf7DkaZKyUiKh9EErS5AZfB4Ct2Rrek2i+By/I4QrOqf7Qm82s39+Wcuxqb QsPjZtxoVnKgrksqGT16zfNa46eNnqXwPmVPLbchWyUHjq8frLR8141TLIlzzUvhDT7k UfSQ== X-Gm-Message-State: AOAM532MNlMqj56YE1dZ1K4fhALBJLK0oUi+tUgO/qxqGa8pjtUSP4IF t7Y2Ogq1odQw0Sa8cU7GfnqWCDSx0YKJ X-Google-Smtp-Source: ABdhPJzxm+jj5EWvAYdKtX2YJJnnLDNfrgC/7WKMyffToJZDquq3DYO27TbqsoOCOfqh0AkV6YTZ7zDrqd13 X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:1cab:1a20:2ef1:ddde]) (user=qperret job=sendgmr) by 2002:adf:fb09:: with SMTP id c9mr8021924wrr.223.1638378293678; Wed, 01 Dec 2021 09:04:53 -0800 (PST) Date: Wed, 1 Dec 2021 17:04:04 +0000 In-Reply-To: <20211201170411.1561936-1-qperret@google.com> Message-Id: <20211201170411.1561936-11-qperret@google.com> Mime-Version: 1.0 References: <20211201170411.1561936-1-qperret@google.com> X-Mailer: git-send-email 2.34.0.rc2.393.gf8c9666880-goog Subject: [PATCH v3 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 Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211201_090455_720839_6375A326 X-CRM114-Status: GOOD ( 13.20 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 c1a90dd022b8..757dfefe3aeb 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) { void *addr = hyp_alloc_pages(&host_s2_pool, get_order(size)); @@ -338,14 +358,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; } @@ -369,8 +389,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) @@ -432,8 +452,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; }