From patchwork Fri Jul 26 23:51:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13743491 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 9392FC3DA4A for ; Sat, 27 Jul 2024 00:10:03 +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=kjY6k542G0oo6Yjo2zUiSEPku2YJftlYNe05DeRMCZs=; b=KHd1f0RFv0zEE4RrJpCH5dNskN lAntgsxS6zZyVA26s8TIB0xnoe5mt1Yp5gitmLRNvHpCYP+rNkOhShmBVSnUKNZCjQOysvATLgoWL PlshK89A5c3XXH5SFJOueympcMhzyPXPaJjK7QZtA0lcf5Q0HwCZLvdQG49BOJSyWxh5Rg8ZEYWSp dyo76SCEERgOuHlPwgdbtT/wpagcBaHDMuFTGp+JSOE9PJhs9/oUz2c8UC71xwqW6YzNO+6AImBEo zCsxaTIrnBrIzm+4wou0zNmNUP468gatJ3AZlvwG+W1cFuTLrvq4WPcIrztBk8n2OQwu+LNp9BOR5 k/CzIC3Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sXV0T-00000005Z4v-3Cgg; Sat, 27 Jul 2024 00:09:53 +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 1sXUl7-00000005QEt-1HJF for linux-arm-kernel@lists.infradead.org; Fri, 26 Jul 2024 23:54:03 +0000 Received: by mail-pl1-x649.google.com with SMTP id d9443c01a7336-1fc658a161bso8412885ad.0 for ; Fri, 26 Jul 2024 16:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722038040; x=1722642840; 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=kjY6k542G0oo6Yjo2zUiSEPku2YJftlYNe05DeRMCZs=; b=bRqKG9Wa+MUKW1vCG0J73XcCzMXMHemQIBdaDy1XerJJT1Nij4D3pVb1IRMYADK4ZR 6Udh+HI0jeMTyGj6eJCw46zuK88teH34OVBVlRvV84TTRpZIE95jwmUD/61b+O5xuzCF gxpkllcoDYIVpZKoHBclWNdFGdubgE+Ie3dApqxsz4vESIc+Q3893trXFkF0+gJnrBKZ 9mKxiR9XdOikVg+BiQb9P/QoIBN0rUuJS1LSOJN0z5VgIK+AZ/XQnGSiqsrjxLdIY9M+ JAGwdLJEF5qlaoT+UkLpiSW4pUUPSRNfLfDKJzaKh7Qn48IzEvFSVNNqDDxXnWt9zEk2 yuqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722038040; x=1722642840; 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=kjY6k542G0oo6Yjo2zUiSEPku2YJftlYNe05DeRMCZs=; b=cA7OjpkrxWLmByN4T750/wMEmIXaVqd5rT1OxlOI9yUt8seEBjQqucWHwIPEUoUx4/ eh3RcLKd2vdfylwyxI3fy1C9+YNyivisD+3Tkv3Tybf17Oze5sfjkwhGQkHfAY3fyDbQ 2/vcv3nHYJE974DqTi74qzsIdnpg4wMgx7TXo/KDQZv8YV2Gu76xRCTG4WeLpzI6rEtZ XoakNATyr2TWcv3U6clfSXcePLq5AAYcIbRmZL76Xt0NmFrqFnTXV/xAn/9ivckIzfjK FkkxLQGyYgtNOW9HKPUi8R1KMp/TcOfrw5hAB/hkk09WRfIM7SP38wlMj93aTIk/+RCC hQPA== X-Forwarded-Encrypted: i=1; AJvYcCUemP2ZqMyjIDaIADvlvcdspANb9Y1S2jQWmq1GzKK8J5QPc6tmIHBgOt6oCr4KUEKYgslX6xzWoWYp6NL3pFSUGKH05trYJWs3Q0CbdnjxccQ4eTs= X-Gm-Message-State: AOJu0Yy2RVrZNtCOK83RWa7Gsmd4t10SaN0KFSoBLRx8St68eIn+qCax kTiisQZUF8skTdis7heZvYCSrzseB3coxp4rX2mk/vfIMcbWM8q9IpnoIhsKDXsMJCRBsSYLyOw U7Q== X-Google-Smtp-Source: AGHT+IHzv0Ay1s7/D5RlCraUOAPppGpx+9DOe5Wc2TnAqa2oJae5LaRq2mY8TBHhwH7zU/okRdoTzatzS5o= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:f60c:b0:1f8:6c64:3575 with SMTP id d9443c01a7336-1ff046dcdffmr290425ad.0.1722038040140; Fri, 26 Jul 2024 16:54:00 -0700 (PDT) Date: Fri, 26 Jul 2024 16:51:49 -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-41-seanjc@google.com> Subject: [PATCH v12 40/84] KVM: x86/mmu: Add helper to "finish" handling a guest page fault 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_165401_386449_27050374 X-CRM114-Status: GOOD ( 12.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 Add a helper to finish/complete the handling of a guest page, e.g. to mark the pages accessed and put any held references. In the near future, this will allow improving the logic without having to copy+paste changes into all page fault paths. And in the less near future, will allow sharing the "finish" API across all architectures. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 12 +++++++++--- arch/x86/kvm/mmu/paging_tmpl.h | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index e76f64f55c4a..1cdd67707461 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4311,6 +4311,12 @@ static u8 kvm_max_private_mapping_level(struct kvm *kvm, kvm_pfn_t pfn, return req_max_level; } +static void kvm_mmu_finish_page_fault(struct kvm_vcpu *vcpu, + struct kvm_page_fault *fault, int r) +{ + kvm_release_pfn_clean(fault->pfn); +} + static int kvm_mmu_faultin_pfn_private(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { @@ -4476,7 +4482,7 @@ static int kvm_mmu_faultin_pfn(struct kvm_vcpu *vcpu, * mmu_lock is acquired. */ if (mmu_invalidate_retry_gfn_unsafe(vcpu->kvm, fault->mmu_seq, fault->gfn)) { - kvm_release_pfn_clean(fault->pfn); + kvm_mmu_finish_page_fault(vcpu, fault, RET_PF_RETRY); return RET_PF_RETRY; } @@ -4552,8 +4558,8 @@ static int direct_page_fault(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault r = direct_map(vcpu, fault); out_unlock: + kvm_mmu_finish_page_fault(vcpu, fault, r); write_unlock(&vcpu->kvm->mmu_lock); - kvm_release_pfn_clean(fault->pfn); return r; } @@ -4641,8 +4647,8 @@ static int kvm_tdp_mmu_page_fault(struct kvm_vcpu *vcpu, r = kvm_tdp_mmu_map(vcpu, fault); out_unlock: + kvm_mmu_finish_page_fault(vcpu, fault, r); read_unlock(&vcpu->kvm->mmu_lock); - kvm_release_pfn_clean(fault->pfn); return r; } #endif diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index e1c2f098d9d5..b6897916c76b 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -835,8 +835,8 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault r = FNAME(fetch)(vcpu, fault, &walker); out_unlock: + kvm_mmu_finish_page_fault(vcpu, fault, r); write_unlock(&vcpu->kvm->mmu_lock); - kvm_release_pfn_clean(fault->pfn); return r; }