From patchwork Thu Oct 10 18:23:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13830923 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 DE8E5CFC5F9 for ; Thu, 10 Oct 2024 19:21:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Reply-To:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:Message-ID :References:Mime-Version:In-Reply-To:Date:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=H+kfG9DgsKWE1QG4Eq/byBdu8SNPmXP5QO3fNGCa8Ok=; b=hhekYX7zpBd1Af 6618tZY1LDH8KOtwZRv5soFinsrUcLDAv2Zv7Ndx12g+Lsy5nRmgPp1khj4rIdcWsOPordB9M9hPC ZAoWOw9lNG+H0fD3CBDpriGhXmX+wNP8UxfI9R5dri08uQGkYc+Q+t+5M+xAUFnm56PDqsf33aGi+ XQ1Hj3P0+oflSCPKq9JEOFQDtRMCAoS+5SZURzrWarojvUFK6CwcwKILFTaqD9een8eWVrXByXM05 7b3WkliwHPLM2eMD7L4MH7M/7IErd8VZrt3Q6oRqwt9nrorOPH/tnumMesLotWGelYEmFBpmhqLqJ f7k5OSDIGgXRli9jZfZg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1syyjQ-0000000E5Zy-3Gfl; Thu, 10 Oct 2024 19:21:52 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1syxrv-0000000DqwN-1o6d for linux-riscv@lists.infradead.org; Thu, 10 Oct 2024 18:26:36 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-6e2e4874925so21251437b3.1 for ; Thu, 10 Oct 2024 11:26:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728584794; x=1729189594; darn=lists.infradead.org; h=content-transfer-encoding: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=BN+hsHae4h8wzhzshUJRGKM30XxzO0F311sC9z4rUGc=; b=mFEQ1pk0GSblJlbvVxjSomWrM6IE+btPApHqV5NrilXRXoFJJ2QtCA8C3DRzZU638K fGwnvg2LFw4lj/o2cvU/G8+4i1rkmzmCYJ+K8kAtgcwfRhJdswGO4ZjYFmc0fOpnGAaO qM8T1NUyZqa09HXc5T1Ol762RIpMtB9T2BxUQSneDHsTS4aPWVdavwKvZRgVyE0BRFlK J2q6XJotNBexnIBUs1cGiNgPYYBQ8CryEKe7aIWrWBYO5N0YgHcBVCFW6MVxRz/ypuMy GI2HAbh6rArHdBxq4xWdbR4NHv2mRM+UDfic7XIfgYAex/UlvCHyl6arPi0UFMRFcmya 8iOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728584794; x=1729189594; h=content-transfer-encoding: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=BN+hsHae4h8wzhzshUJRGKM30XxzO0F311sC9z4rUGc=; b=kwLtYtPH9kC97pnEJWI8/Hk8NT5idk5ghw716bD0fLNT1xmNsANU3thZrIhcShdKBV kLH797qai++XZhII5Xe2Tbm8rPXmdMB405NlUdI6rkJEpBcv0I4AVUpaimTvpwBVs/rW ZrF7iBTg7L+JWPd3J6X+hL45CsYfieTnsD/8/vO9NYl8jaF3xEjwUS6ytHmPDXz9Jf6O HRTNFwwuG5SeiS5lAr5YoawwKBlHNqwNg9YuWtbg9QvatZVAZJ/dLT35/ZW8qWnyD+m+ ucTe38h8uDJ2AZ6QJSJmJu8iZTah5ZpMVmnEz6xeiEUZe4kcBiQO3oZ567+J4yAc2kbd iNNQ== X-Forwarded-Encrypted: i=1; AJvYcCW6oSmZkZfHJ099hCZuA/6pljZQLmZLYScv50R1hGlY/M+Gm5bnOdzfC6bXrS3JQSrSqZp59nygI2M4PQ==@lists.infradead.org X-Gm-Message-State: AOJu0Yy+smQTg9AYa38NZjynDuOk+Fu6KDzBptl0W5JK+xo5uuRwm6n+ 9qQpMzrgpClr073Ns/DggzN9pJeEgpMANT0Bg4KFr2qzCpwsrVpRedCvs/99K2ecEryJf+2zA5u 92w== X-Google-Smtp-Source: AGHT+IEjw5s9ln5Mmco0bHKHDYNNIWwRc71SIREcZZABOz/fcRYPRAU5+BeNEqASF/uZrX6+QTap8C7eoHE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a05:690c:2c01:b0:6e2:3e17:1838 with SMTP id 00721157ae682-6e3221407b0mr440167b3.1.1728584793806; Thu, 10 Oct 2024 11:26:33 -0700 (PDT) Date: Thu, 10 Oct 2024 11:23:50 -0700 In-Reply-To: <20241010182427.1434605-1-seanjc@google.com> Mime-Version: 1.0 References: <20241010182427.1434605-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241010182427.1434605-49-seanjc@google.com> Subject: [PATCH v13 48/85] KVM: x86/mmu: Don't mark unused faultin pages as accessed 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, " =?utf-8?q?Alex_Benn=C3=A9e?= " , Yan Zhao , David Matlack , David Stevens , Andrew Jones X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241010_112635_500860_87311F51 X-CRM114-Status: GOOD ( 11.86 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org When finishing guest page faults, don't mark pages as accessed if KVM is resuming the guest _without_ installing a mapping, i.e. if the page isn't being used. While it's possible that marking the page accessed could avoid minor thrashing due to reclaiming a page that the guest is about to access, it's far more likely that the gfn=>pfn mapping was was invalidated, e.g. due a memslot change, or because the corresponding VMA is being modified. Tested-by: Alex Bennée Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index f9b7e3a7370f..e14b84d2f55b 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -4386,7 +4386,9 @@ static void kvm_mmu_finish_page_fault(struct kvm_vcpu *vcpu, * fault handler, and so KVM must (somewhat) speculatively mark the * folio dirty if KVM could locklessly make the SPTE writable. */ - if (!fault->map_writable || r == RET_PF_RETRY) + if (r == RET_PF_RETRY) + kvm_release_page_unused(fault->refcounted_page); + else if (!fault->map_writable) kvm_release_page_clean(fault->refcounted_page); else kvm_release_page_dirty(fault->refcounted_page);