From patchwork Fri Jul 26 23:52:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743571 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 CF7E9C3DA4A for ; Sat, 27 Jul 2024 00:31:17 +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=M9eYn37tam32k4Zpbs9VqSvLY6wlhZ916YFlgyF6peA=; b=12UZKvraL6WRqIG1B3TbbOBGvl 451/mYaIJBoGF6Ml2yla6MeTmEbW4jNd0TJ8XKKc7YoQwY5bLmEQ8vfTdEEfgL5T/55LKNOx+IYSO 07miOo88JgqHQFxZNa/f64lp3g5S2Ip37C7WHeVKzZ17/n71zCrZqLcZNFOAFzJy+RnN8vQRzKPOG /bcuX8g9PybdCPAkpPRWxhkH76OxowI8QTEeOplmuvSbkNQJcGW+OLvndH1bGiB75+P4yz+G2wjrU IfmI99tNE5YiNaYUoFjNYFPs17xhB2k40rAZKSrekWd+xuYFQNPTAPYu1P8mSZ2GUtJCUEz2L0QKm xTDXmCXA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVL1-00000005jDi-3kj5; Sat, 27 Jul 2024 00:31:07 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXUmE-00000005RDZ-2gzf for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:55:16 +0000 Received: by mail-pg1-x54a.google.com with SMTP id 41be03b00d2f7-7a134fd9261so1531589a12.3 for ; Fri, 26 Jul 2024 16:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038109; x=1722642909; 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=M9eYn37tam32k4Zpbs9VqSvLY6wlhZ916YFlgyF6peA=; b=c0WShnEqI9zybJMiCXTEfvNq8PbWYMebI4kgiVVwpmOZ0PklDW2FgMa5BegC7dCDVK q3fvPXR5Mp0S2Uk0lS2eDICFnhKEY/sSMVMUpptwy+j7/v+d0Czuuv9rOY7W8o/pR30P pDvwDOBaWprvTc31K55pdNv8UpzGNDLUNnpSPrwK6lFJYvclZmK9YwIW+BXyl37GOdG5 RDtvAQSYqZq4YblJKUwRdZIFrPyb1bKkz9/SSytJWZnRjbcLIA94AL2JSQjsRhFPv972 KmcnvJ375ftGwTqp0f2htzpPJeOf6A5CtExNMTOXUjI+YQAvdNc6xb4YiNOu9eIToI9k KXiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038109; x=1722642909; 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=M9eYn37tam32k4Zpbs9VqSvLY6wlhZ916YFlgyF6peA=; b=ttAkbmsZGBCJ+9M3ZJYhm96n9BaRt8lx2pi9tfeUAF/q74rM8hHfux7H/BLanTUu/l OUtBsiE9GVmjvMgxuvPUBZUP6m6YYnJT9PcbBNyFNfSl7rmTPOb18p6LLkGL1xMbAW9e 7pJu1zthCGAYD+gGFkJQVkdv+4dnjcbA5wM/oVyGWIT18Ucs2nhToLySJz3fNJMfskkJ W5pl1eQwE2Dy4no1TzqNbcDDCO5DKudUTCd1REVNxjrTKQD70cY3tofstwvFbg6ixGh4 UEwv+q4RJUYFVmU6FXrTVM/3MRkhpbRMYXGFQhprLVjKty5tmMY+XAEY4oA+8c1zaSmw uTvA== X-Forwarded-Encrypted: i=1; AJvYcCWDaiimHfT0nbfhMBxvwrT27jjRQlb8MrAsGiocEFYrr7YX0CEIsmhuSMxgf+UBfzWQlSAFuD/mm8diiVxsxj85SJjqhrJHAStm1LTvS/IoG1yMfBw= X-Gm-Message-State: AOJu0YwRAT5HpbTQ1y9p3m1pDTlsexj73DW1vSgb81X2CpylNh51OlrG L55joOQZngqsgx6AmooTkb2VOgMO6uPq8J0suj67Q8+JbhslazQTf4XfaZR5wa1XEhWrXH+FASO 98Q== X-Google-Smtp-Source: AGHT+IG8TH3qPrjAadwsmfbGVL51l5vDfwJrWL4CCM6knLIepOGyFeiwzAiBROJulbOiIHONd5UuXBO9hTI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a02:526:b0:6e3:e0bc:a332 with SMTP id 41be03b00d2f7-7ac8dbc497emr2439a12.2.1722038105187; Fri, 26 Jul 2024 16:55:05 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:20 -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-72-seanjc@google.com> Subject: [PATCH v12 71/84] KVM: MIPS: 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_165510_918553_FFF2900D X-CRM114-Status: GOOD ( 13.64 ) 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 MIPS 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/mips/kvm/mmu.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/arch/mips/kvm/mmu.c b/arch/mips/kvm/mmu.c index 69463ab24d97..d2c3b6b41f18 100644 --- a/arch/mips/kvm/mmu.c +++ b/arch/mips/kvm/mmu.c @@ -557,6 +557,7 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, bool writeable; unsigned long prot_bits; unsigned long mmu_seq; + struct page *page; /* Try the fast path to handle old / clean pages */ srcu_idx = srcu_read_lock(&kvm->srcu); @@ -578,7 +579,7 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, 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 + * in 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. * @@ -590,7 +591,7 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, smp_rmb(); /* Slow path - ask KVM core whether we can access this GPA */ - pfn = gfn_to_pfn_prot(kvm, gfn, write_fault, &writeable); + pfn = kvm_faultin_pfn(vcpu, gfn, write_fault, &writeable, &page); if (is_error_noslot_pfn(pfn)) { err = -EFAULT; goto out; @@ -602,10 +603,10 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, /* * 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); goto retry; } @@ -632,10 +633,7 @@ static int kvm_mips_map_page(struct kvm_vcpu *vcpu, unsigned long gpa, if (out_buddy) *out_buddy = *ptep_buddy(ptep); - 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); out: srcu_read_unlock(&kvm->srcu, srcu_idx);