From patchwork Fri Jul 26 23:52:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743543 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 6ECDBC3DA4A for ; Sat, 27 Jul 2024 00:22:57 +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=caIg6eZHDZieCZ2y8TnIGsflH+xvFOT1i8qMSVM8X2U=; b=aDS8VF7e+52HqWYcvPUyDFAlIn GpLKHU0icibPTODnAPuo9qEo3xgQDcGr5FxxiJ57glEIYa3bJNLhIj6dPyvfK7CJIdysdfUdCcCu9 RZr5PMllbpwJVf/LE0VdAZkxOS0uIaN5UrXPgrYpxOdhlbJObrU22wa9eZc7nUo81EfYiHesODe0e 6eCeVa2HmDIFNzNI3kTm5+12PI5bcY+Gzm2ryLAe+eBQM569N+04DjaZmnAgYVCNd57KbpG8VIuFm xgvpRk/G/ebDbHK/RogrofhHZ6znvobJmle9EsLCxwa5x7muvPQTxmK9lprPYQWY35I3mOXTU992t qXccbohg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXVCx-00000005fKW-2Huc; Sat, 27 Jul 2024 00:22:47 +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 1sXUlc-00000005QgS-1Zwr for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:35 +0000 Received: by mail-pf1-x449.google.com with SMTP id d2e1a72fcca58-70ec1039600so1046823b3a.0 for ; Fri, 26 Jul 2024 16:54:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038071; x=1722642871; 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=caIg6eZHDZieCZ2y8TnIGsflH+xvFOT1i8qMSVM8X2U=; b=L6Vh7A+BONb2dq+by+MhTfWBD5KMq4ZcbNgL1qRWH/8nRuuhZk7mFKHCjuL6pdpIg7 UKTcSULbYwg294JRCwDcMDw3Wt4T7qawJZCJ2ZJVqkow//bFaAud1wxv3eBCvLpy/rSc tbLPJWPHv8CYL/6r2LMX6xKCS+NG+QF+UbYp4OeJUHuGIrYIvii2PcYtuYmv8dH0hA8u HYf2YWdrPREUt61XQyEnKLmWcnqnHG8b8nqGnRJHuK56INLZ3TaOMCMlPE2cGEpZqO98 p4S8C7J4UYrMM+AhNyRrTll8edZIKnIdnnTvYSWIrfqiJ1sZ1zlE4q7X5gj+oPceBGlg HWDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038071; x=1722642871; 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=caIg6eZHDZieCZ2y8TnIGsflH+xvFOT1i8qMSVM8X2U=; b=PwO07SG6bVloOYsIsEUTmgXi6CnF6+YVSFjyqRtWL3yJTHq6Pts+Maq7qksw/pfHe8 C7PjYJfTMLCv1tTkkcn325vbG9dLVNXou2dVEOS0WhKD7Ix1JgaVfg4ECR4ijWXJfU84 EhOJow3nh1myT57+orMojPEKYPOdTlteH9D75eb+NNUA4uxTWo8GLBsJHeoN06P+0tMR V/XNacWmulQuNp5eI8YybbciaGmir+Rz4zSfWKwC/LXJcq7PfZ6kiBvK3Ljg4M7DHigC YhOISXup38XABgLks26UTX+cw/CWVvf7JabUX3L8mC15hQuHHJiQqjNGDdT5cCQVZgkl hkhw== X-Forwarded-Encrypted: i=1; AJvYcCUECFY6/naw4tDhPBU7CNSeeX5sfs01WxB0TWl1tr2zdEzpwn62SKtvrmJhABbaPJl0yCfaXubXXxT5TIrYL+gyAoaJzSLtJQboIT+NvobwvL9wIGY= X-Gm-Message-State: AOJu0YwVM/zTRRufOeHzyfoioRnCI1qw7pNqBDGEo/AJZTm6WO26FzL5 nDwPXqrIMUgvbQvzhgiBzuGyafodjd2jFYhKamolRS6VyAGXn/+8JsFVnGgAqCR+ZP23RInziaY Yww== X-Google-Smtp-Source: AGHT+IFCpL56eroYNOyLiVhUcT5fyuFzA98b59p62FwWY/A7pZmePwqTF4FXfEto2ywMz9XC9lExu2Xr4CM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:9445:b0:706:3421:740d with SMTP id d2e1a72fcca58-70ece9ecf02mr25759b3a.1.1722038071004; Fri, 26 Jul 2024 16:54:31 -0700 (PDT) Date: Fri, 26 Jul 2024 16:52:04 -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-56-seanjc@google.com> Subject: [PATCH v12 55/84] KVM: arm64: Use __kvm_faultin_pfn() to handle memory aborts 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_165432_597712_7FC4A6AA X-CRM114-Status: GOOD ( 13.88 ) 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 arm64 to use __kvm_faultin_pfn()+kvm_release_faultin_page(). Three down, six to go. Signed-off-by: Sean Christopherson --- arch/arm64/kvm/mmu.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c index ce13c3d884d5..756fc856ab44 100644 --- a/arch/arm64/kvm/mmu.c +++ b/arch/arm64/kvm/mmu.c @@ -1439,6 +1439,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, long vma_pagesize, fault_granule; enum kvm_pgtable_prot prot = KVM_PGTABLE_PROT_R; struct kvm_pgtable *pgt; + struct page *page; if (fault_is_perm) fault_granule = kvm_vcpu_trap_get_perm_fault_granule(vcpu); @@ -1553,7 +1554,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, /* * Read mmu_invalidate_seq so that KVM can detect if the results of - * vma_lookup() or __gfn_to_pfn_memslot() become stale prior to + * vma_lookup() or __kvm_faultin_pfn() become stale prior to * acquiring kvm->mmu_lock. * * Rely on mmap_read_unlock() for an implicit smp_rmb(), which pairs @@ -1562,8 +1563,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, mmu_seq = vcpu->kvm->mmu_invalidate_seq; mmap_read_unlock(current->mm); - pfn = __gfn_to_pfn_memslot(memslot, gfn, false, NULL, - write_fault, &writable); + pfn = __kvm_faultin_pfn(memslot, gfn, write_fault ? FOLL_WRITE : 0, + &writable, &page); if (pfn == KVM_PFN_ERR_HWPOISON) { kvm_send_hwpoison_signal(hva, vma_shift); return 0; @@ -1576,7 +1577,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, * If the page was identified as device early by looking at * the VMA flags, vma_pagesize is already representing the * largest quantity we can map. If instead it was mapped - * via gfn_to_pfn_prot(), vma_pagesize is set to PAGE_SIZE + * via __kvm_faultin_pfn(), vma_pagesize is set to PAGE_SIZE * and must not be upgraded. * * In both cases, we don't let transparent_hugepage_adjust() @@ -1685,11 +1686,7 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, } out_unlock: - if (writable && !ret) - kvm_set_pfn_dirty(pfn); - else - kvm_release_pfn_clean(pfn); - + kvm_release_faultin_page(kvm, page, !!ret, writable); read_unlock(&kvm->mmu_lock); /* Mark the page dirty only if the fault is handled successfully */