From patchwork Fri Jul 26 23:52:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743553 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 6B047C3DA49 for ; Sat, 27 Jul 2024 00:27:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:Cc:To: From:Subject:Message-ID:References:Mime-Version:In-Reply-To:Date: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=rpwXsNxFJqP0CEr/yEQ2h0r+lN6KBTuvETCSKMoe8FQ=; b=rleox2V5aItkSs6Kvk9iBFqE5D JKMxm2WtyvqZNPtn46Um4MzNgU/5h9L/Xx1lH9zxQ3EromgIMCL6o4rwAMv3ISDXXKaDnKgA3MToR Yt0qShzoNpZXo958F6+BLqqLMDB6N6aXWoZ2a1X/qIZeF56iIEgmozLfGkG9ZkjB4ANJSRtA6Ofma Qm5rM+so7DDRM54PtbScUyA+yg+fHb0ENHv2r4dqLb731XAwtCYgQuuxMdrwBZ0o1HhWLNMhC/c0a rIUfvswRILu1Sytq2+OTMIXDVsab32d+G7lt1HuBM0237Hg4P7IcGDJZvpVIupM/ktaCTTMg084BU Zz1pInrg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVHK-00000005hNb-1a13; Sat, 27 Jul 2024 00:27:18 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUly-00000005Qx4-1zfv for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:56 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1fed6fe8002so10219975ad.2 for ; Fri, 26 Jul 2024 16:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038093; x=1722642893; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=rpwXsNxFJqP0CEr/yEQ2h0r+lN6KBTuvETCSKMoe8FQ=; b=zGcKry2mcen4CZCTkukKs+Nhk9bKhk+SJbteeryNgOFo0gyHXiHTxSTM6ZutJQX8a+ wbkVzTV6013wnb3qCfljUXVSo0MGKnJBug97IFf/qIuj73/edTdpt6XyQK1pVuVNruu7 vFaMY7lXdOF4zgtKGrBhlCqbkRZgS7+oaE0KY3dqNZAmWcI68rz0tyWjGh1GLzdVTET8 0d2gW0Eb6+CDTyD9FqMIGZqCH5pa5BdjnJqtkG9mt9R9706NgU2BqS0QopRpEEykp+Wa T7IuV5H6inMrQLUD+mR/v7iRJ+WZrtb0y8QEznkeIzIu5jfH8V1mcdIXbvmRqx0fTQ78 51eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038093; x=1722642893; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rpwXsNxFJqP0CEr/yEQ2h0r+lN6KBTuvETCSKMoe8FQ=; b=l0OS8fnFara7WYiXhil3wIc1Kjj2OyQyfg10YoLZ/2G7tUxhFQZQKGCKzSHPHvm4Xu C9uBc0Hx+V9inHIgvcX1s3aTRR+c/1+BrKtuViYtgbYxmIC/p3vZcfOVF97ZFS+RLXP5 w7zGFU084tee9BcVGMDQBieaSRbfTAwATv66VipOU9TJ+S3MAZ/cDxpGS+XaZgZV2M0+ 38hQUAKKpHYLQdXo9wfiMWjF4xgxEv8OkGHi1RqJI+V+pAMu5xgNN1TRZHu5WozAJM8Z dOchpF8wX/TFLyaYVAnfOLz8KmBC8F88m5jQtml/NxHk2EDTpxxvz+J5Fn0SXJ01ZKHE QvEQ== X-Forwarded-Encrypted: i=1; AJvYcCWvA2RNKSLm3zpiN+Z8VybRxFEWm8p0OV1KOzXXDkytEH8oTJ/BOiJh5zu6ThIyvJW0MZZtzW1gy+GAF7sz00gKd6WEWHM6yOAw+AJLGxC8vnGgcuM= X-Gm-Message-State: AOJu0YzCHOFOOwnQuUn+Gia0Qnsyh4Ez1psnqiqcNEoxTRUBjaV3fUor hbAvzqxZBONyzytVB+iWciDJ0FNJhrChYBxo0AJ8qoa9Z0DYtyGivOJ109OqsN8cStnHgn7JnjZ lOQ== X-Google-Smtp-Source: AGHT+IEz1qMb/9xSOR6pziERGmR6RlcO2d1FpOxR3ZCse98fOqCGJ5ia3ZBUMMNkI3e0ioyh2oD8FsbOxx8= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:903:2341:b0:1fd:63d7:5d34 with SMTP id d9443c01a7336-1ff04803eeamr27405ad.5.1722038092373; Fri, 26 Jul 2024 16:54:52 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:14 -0700 In-Reply-To: <20240726235234.228822-1-seanjc@google.com> Mime-Version: 1.0 References: <20240726235234.228822-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc1.232.g9752f9e123-goog Message-ID: <20240726235234.228822-66-seanjc@google.com> Subject: [PATCH v12 65/84] KVM: LoongArch: Mark "struct page" pfns accessed only in "slow" page fault path From: Sean Christopherson To: Paolo Bonzini , Marc Zyngier , Oliver Upton , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Sean Christopherson Cc: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , David Stevens X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240726_165454_764998_96C03C79 X-CRM114-Status: GOOD ( 13.46 ) 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: , Reply-To: Sean Christopherson Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Mark pages accessed only in the slow path, before dropping mmu_lock when faulting in guest memory so that LoongArch can convert to kvm_release_faultin_page() without tripping its lockdep assertion on mmu_lock being held. Signed-off-by: Sean Christopherson Reviewed-by: Bibo Mao --- arch/loongarch/kvm/mmu.c | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c index 364dd35e0557..52b5c16cf250 100644 --- a/arch/loongarch/kvm/mmu.c +++ b/arch/loongarch/kvm/mmu.c @@ -552,12 +552,10 @@ bool kvm_test_age_gfn(struct kvm *kvm, struct kvm_gfn_range *range) static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool write) { int ret = 0; - kvm_pfn_t pfn = 0; kvm_pte_t *ptep, changed, new; gfn_t gfn = gpa >> PAGE_SHIFT; struct kvm *kvm = vcpu->kvm; struct kvm_memory_slot *slot; - struct page *page; spin_lock(&kvm->mmu_lock); @@ -570,8 +568,6 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool writ /* Track access to pages marked old */ new = kvm_pte_mkyoung(*ptep); - /* call kvm_set_pfn_accessed() after unlock */ - if (write && !kvm_pte_dirty(new)) { if (!kvm_pte_write(new)) { ret = -EFAULT; @@ -595,23 +591,11 @@ static int kvm_map_page_fast(struct kvm_vcpu *vcpu, unsigned long gpa, bool writ } changed = new ^ (*ptep); - if (changed) { + if (changed) kvm_set_pte(ptep, new); - pfn = kvm_pte_pfn(new); - page = kvm_pfn_to_refcounted_page(pfn); - if (page) - get_page(page); - } + spin_unlock(&kvm->mmu_lock); - if (changed) { - if (kvm_pte_young(changed)) - kvm_set_pfn_accessed(pfn); - - if (page) - put_page(page); - } - if (kvm_pte_dirty(changed)) mark_page_dirty(kvm, gfn);