From patchwork Fri Jul 26 23:52:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743565 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 8584FC3DA4A for ; Sat, 27 Jul 2024 00:28:24 +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=T3Tq4gPotkzFIpSFFawcUtCGWBlTwHcibbE0IfTBXb4=; b=MMaA8dBoxe442SL/YLuOsJAGt9 6LYHqGJ90T+7qRdX8GEVoeBobnCrT4o/Ihiv4YAucFlP7OUdGvENn9i9VgFWJK/uC9vhKIbQ4lhtG gz4lRtdsYY6Huc8NzHPiXf2+rEMJITk3YI89yXnCoWuuCVCY4dIfa4RH1bKv9z60NjXRbGPEUPUQa OuOz9YD9HeMnQN3GeQ2B3Mur+8WER66fNjZhiaNrWuttF35paO5nlIlcElWYYsXcaZLCF6qzfVp76 BtiCS7OVL3Nl0rEiW0mDSBcRgk6eGbn6hBas1gAuBDHIgEtjkGIq8Br8V3CId4XVDyxX6CPNtsJQ8 L9T1xMhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVIC-00000005hoW-3ICW; Sat, 27 Jul 2024 00:28:12 +0000 Received: from mail-pf1-x449.google.com ([2607:f8b0:4864:20::449]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUm1-00000005R0w-3nUf for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:59 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-70d14fc3317so1434781b3a.1 for ; Fri, 26 Jul 2024 16:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038096; x=1722642896; 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=T3Tq4gPotkzFIpSFFawcUtCGWBlTwHcibbE0IfTBXb4=; b=BhozBO0kEAfCrIflS0Go8lh9e/ZB2mWScYCllqepSY29Ygi9IwPBSE7Go//e4lAwUU mX28kBjKeJK8fHod/iMvcLezmzW3+aHE83hYJ5u4W8AbuTbatNysH+4wBVR1lHx+4YfC ubXiFv8w3D9XeWYXz6xCBhByBf5kbBSVO3ZaNNhJrIs7pv1NVY2bjNDSU42JwJZ+sZPE pAWJ5khc6WOuQNNpRnD0dZ4i+fUpsXJDwiYpZF+2mz1lK6M6PFNkzOY1Rm6VG0tuxpg2 P6skP2qkjFW/K5T682nNAXt+8Sq1oZNBUrnbRPcaIxARwjEtXzyHOUiM9oal9T5MSyvg gwzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038096; x=1722642896; 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=T3Tq4gPotkzFIpSFFawcUtCGWBlTwHcibbE0IfTBXb4=; b=VkFftHFCSqspbnw9l6F4uOHSnsXpJWG8E8h94of2OoqKM2MzEXWVuX39Kigpk83TGu UJNfQUv35EOk3bLzackLoCwlAEhKdiHHH1pzZWz0bf2tSEmLLfYj/gcZWqZnFh9d2NzH wyMh9yl87U2g7iOXaDmd9iQaU4hNGXzpcFhbwfcm0IsNKcSjWxsqo9wS04DSABu4r/pH m2oNRv6Cz0UbqDSWddBZNt48THWL7zwjZr02hRG4HB8RUWjdSEquBJFIiExdidWNDzoz cSehjEMtGWqy22JmjWzhyDMd0xXAL5IheW1INXhYBxo2IDOJJqAp5Ixr6wW702Y+0Upp 1t9Q== X-Forwarded-Encrypted: i=1; AJvYcCXMjnCqmuZxtQOiYMDl06B81uHCYsAJjFTqLGOz883rpKQ/0P4yK8CogonmFtvbs3msiZjMOWmFJYMVRjpVAS1U58oQh53AUs/Mn8eksfkvdT17Cmg= X-Gm-Message-State: AOJu0Ywma+0eC86CunrxiEAVDuFC57nQl7iayrSijtdWDJmupLZlb/3X Tdi831cn1deJurmPyw0iO3QmB94jAkfMKCOYugaaCDQWZmwN7zq0vEuqEogOiuUuQKowW3AtQFH p7w== X-Google-Smtp-Source: AGHT+IExCpdv69na3gU93uhAEfGJO0DgmCPrxQU8TmhxNm9ObFOOTchJQQycuTaWmcpCMOvBszJjylffDDY= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:2d99:b0:70d:2b2a:60f7 with SMTP id d2e1a72fcca58-70ece928763mr9066b3a.0.1722038096309; Fri, 26 Jul 2024 16:54:56 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:16 -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-68-seanjc@google.com> Subject: [PATCH v12 67/84] KVM: LoongArch: Use kvm_faultin_pfn() to map pfns into the guest 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_165458_291663_32BEADDD X-CRM114-Status: GOOD ( 14.21 ) 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 Convert LoongArch to kvm_faultin_pfn()+kvm_release_faultin_page(), which are new APIs to consolidate arch code and provide consistent behavior across all KVM architectures. Signed-off-by: Sean Christopherson --- arch/loongarch/kvm/mmu.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/loongarch/kvm/mmu.c b/arch/loongarch/kvm/mmu.c index 230cafa178d7..83e4376deabb 100644 --- a/arch/loongarch/kvm/mmu.c +++ b/arch/loongarch/kvm/mmu.c @@ -780,6 +780,7 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write) struct kvm *kvm = vcpu->kvm; struct kvm_memory_slot *memslot; struct kvm_mmu_memory_cache *memcache = &vcpu->arch.mmu_page_cache; + struct page *page; /* Try the fast path to handle old / clean pages */ srcu_idx = srcu_read_lock(&kvm->srcu); @@ -807,7 +808,7 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write) mmu_seq = kvm->mmu_invalidate_seq; /* * Ensure the read of mmu_invalidate_seq isn't reordered with PTE reads in - * gfn_to_pfn_prot() (which calls get_user_pages()), so that we don't + * kvm_faultin_pfn() (which calls get_user_pages()), so that we don't * risk the page we get a reference to getting unmapped before we have a * chance to grab the mmu_lock without mmu_invalidate_retry() noticing. * @@ -819,7 +820,7 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write) smp_rmb(); /* Slow path - ask KVM core whether we can access this GPA */ - pfn = gfn_to_pfn_prot(kvm, gfn, write, &writeable); + pfn = kvm_faultin_pfn(vcpu, gfn, write, &writeable, &page); if (is_error_noslot_pfn(pfn)) { err = -EFAULT; goto out; @@ -831,10 +832,10 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write) /* * This can happen when mappings are changed asynchronously, but * also synchronously if a COW is triggered by - * gfn_to_pfn_prot(). + * kvm_faultin_pfn(). */ spin_unlock(&kvm->mmu_lock); - kvm_release_pfn_clean(pfn); + kvm_release_page_unused(page); if (retry_no > 100) { retry_no = 0; schedule(); @@ -900,10 +901,7 @@ static int kvm_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool write) ++kvm->stat.pages; kvm_set_pte(ptep, new_pte); - if (writeable) - kvm_set_pfn_dirty(pfn); - kvm_release_pfn_clean(pfn); - + kvm_release_faultin_page(kvm, page, false, writeable); spin_unlock(&kvm->mmu_lock); if (prot_bits & _PAGE_DIRTY)