From patchwork Fri Dec 2 18:51:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oliver Upton X-Patchwork-Id: 29084 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1024164wrr; Fri, 2 Dec 2022 11:04:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf5sX8/xTEDR7dBh9R2TqrFspAeEak9SlDNm+me6tbvS6dh8eantjuwpjmYLsK6LvQvtG0gR X-Received: by 2002:a17:906:f857:b0:7c0:85ff:d3ee with SMTP id ks23-20020a170906f85700b007c085ffd3eemr16201841ejb.633.1670007889516; Fri, 02 Dec 2022 11:04:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670007889; cv=none; d=google.com; s=arc-20160816; b=OmEcmg+vye2em+fsKqSnQnktIMPNgRQ7eLqckkohr8u7wauXTF1oAQEK0pykX7S8uE Z2HkA3ccMzziy33AF0ccVRoS8XmKmZIzV1gm1mjjnlNLyMi7G9sLaySkEjUrSXqVVK1j Ol8x4Uby+4k/EtI7148oFf/CSQWZIkkIxqxA0BfIrkznltU0ijKrGJE5vN7YOGYDLrjL t8+0DT9m4ivUetrewnTzDPdJPxbBC+VTywPjiceUwdsIx5pC6BqmvTlRA7KWFDJW+s6z 9AXdFArtVJ7Bzjj2D6r2MIlwWqRN8ai6LBFPhSCqGlqLhYiYN9R0odmgqZwlAH9C+FpP 934g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=36q34GkAdZNcp02VfFJ/fMceb+GlTAxgwL6t8UJ/nCU=; b=NPbKBrfMcTvr5HReyilSUVcPrts7QqTi366HBcNlMNKVX+NDy373usSEhMjb2Lkhl7 3m8bww8mQ+nia5B2F8w4ZvQQ5+hNNuivjMR3kGeiSV0bpS1UA0jgfVBc2LQCVC3nzfAA HjXZc2Bb+MMcvcTl/YfsaFs7C2TcBCvZTAcV4rsIrj4DAS/eLuaPIDeTAMSSQJPJc3h6 qwCion/VTCzrPpSYjWSTazHTfWXaxRNJxBIfXJXnt5bpdYdtS1ijK5ap+f6CYB5PG0Ef 0I8bpOikuq5rypcIVpAMeuQf9r22rGYZuQnjg92dUXaHT3B/wrgXDvxhglAr44I18Mt2 rE4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LAPfFRXk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r24-20020aa7da18000000b0046314dd20a0si1958491eds.3.2022.12.02.11.04.26; Fri, 02 Dec 2022 11:04:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=LAPfFRXk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234740AbiLBSwp (ORCPT + 99 others); Fri, 2 Dec 2022 13:52:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234699AbiLBSwg (ORCPT ); Fri, 2 Dec 2022 13:52:36 -0500 Received: from out-182.mta0.migadu.com (out-182.mta0.migadu.com [91.218.175.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48461EAB52 for ; Fri, 2 Dec 2022 10:52:28 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1670007146; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=36q34GkAdZNcp02VfFJ/fMceb+GlTAxgwL6t8UJ/nCU=; b=LAPfFRXkfCOfssjRADm7/jdYZ7LQl2uW9dy14PfWeo2914srk2DSSW7OAI1GrB7JEscgbY DxllYbdQAX26FIFaFFLzCntc4Uhua5fSy2WeUOjvTWcv81z6joZgp064csO8ICW67kHF+9 cSAdicod8mmQR59+MNnYmUOZe79b8Wc= From: Oliver Upton To: Marc Zyngier , James Morse , Alexandru Elisei , Suzuki K Poulose , Oliver Upton , Catalin Marinas , Will Deacon Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, kvmarm@lists.linux.dev, Ricardo Koller , linux-kernel@vger.kernel.org Subject: [PATCH v2 5/6] KVM: arm64: Handle access faults behind the read lock Date: Fri, 2 Dec 2022 18:51:55 +0000 Message-Id: <20221202185156.696189-6-oliver.upton@linux.dev> In-Reply-To: <20221202185156.696189-1-oliver.upton@linux.dev> References: <20221202185156.696189-1-oliver.upton@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751130193120811503?= X-GMAIL-MSGID: =?utf-8?q?1751130193120811503?= As the underlying software walkers are able to traverse and update stage-2 in parallel there is no need to serialize access faults. Only take the read lock when handling an access fault. Signed-off-by: Oliver Upton --- arch/arm64/kvm/hyp/pgtable.c | 3 ++- arch/arm64/kvm/mmu.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c index aa36d896bd8c..30575b5f5dcd 100644 --- a/arch/arm64/kvm/hyp/pgtable.c +++ b/arch/arm64/kvm/hyp/pgtable.c @@ -1120,7 +1120,8 @@ kvm_pte_t kvm_pgtable_stage2_mkyoung(struct kvm_pgtable *pgt, u64 addr) ret = stage2_update_leaf_attrs(pgt, addr, 1, KVM_PTE_LEAF_ATTR_LO_S2_AF, 0, &pte, NULL, - KVM_PGTABLE_WALK_HANDLE_FAULT); + KVM_PGTABLE_WALK_HANDLE_FAULT | + KVM_PGTABLE_WALK_SHARED); if (!ret) dsb(ishst); diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index dd8c715f0775..25e18e1d9a15 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1406,10 +1406,10 @@ static void handle_access_fault(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa) trace_kvm_access_fault(fault_ipa); - write_lock(&vcpu->kvm->mmu_lock); + read_lock(&vcpu->kvm->mmu_lock); mmu = vcpu->arch.hw_mmu; pte = kvm_pgtable_stage2_mkyoung(mmu->pgt, fault_ipa); - write_unlock(&vcpu->kvm->mmu_lock); + read_unlock(&vcpu->kvm->mmu_lock); if (kvm_pte_valid(pte)) kvm_set_pfn_accessed(kvm_pte_to_pfn(pte));