From nobody Sun Feb 8 06:40:18 2026 Received: from mail-pl1-f202.google.com (mail-pl1-f202.google.com [209.85.214.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BA77954652 for ; Fri, 2 Aug 2024 20:39:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631147; cv=none; b=gE7U9fAOGgc9lSE8Qb239xx/uXsRfiLI1xOJgtNeC6MB3OmMqXaHe9eNioTVpm+gUE00Q4560Vmt2yU423W6UkydmKNvVwyb3R13dbbAk638K9L4EKUF6UY7447yHaNNjFhlevGAMfUiiMpdXJwUT96P7lCvinhELEqS8iFl0/8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631147; c=relaxed/simple; bh=uEQJJy35Z3zwuI3RWRH09lvrxnJ9BdiLiESax8ufYG8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=rgxlPLpMGuLRTPkmiKAq0CwkAfDn99cp0cklZDcR0kdfrrFd+Bksq6gfFHGzHMckBjrFxS2yZzjuqd0ps3mx2NLp2k6gMYralVwxURAJxTaJrH7vT1STcTQnxIPEJDgxcvEJf0jYssgUptYmwZij9tW59zVBGDrm8fKvuJqRT2U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=AMkR73z/; arc=none smtp.client-ip=209.85.214.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="AMkR73z/" Received: by mail-pl1-f202.google.com with SMTP id d9443c01a7336-1fc51ea72abso82896915ad.1 for ; Fri, 02 Aug 2024 13:39:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722631145; x=1723235945; darn=vger.kernel.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=OaXT0AL8GbS9YXbDGbiDFqWt3txOFoZxKOINxRCY5SE=; b=AMkR73z/J+xfKTo4+2KJ10lIM8b8ESsXGC09sH6vuOKyBK+95ZuBVzIn87e6p1jZo/ pZ897iyZDJRVpLCQJBxfEEUyFKKOgq/wZ8m2X3LycIo6fWKzR/IsO2Yiw2xBUDSQ+scA PqJgufQpAx5eEO/FkyUwOvnBXiFslWPyzia3njes6g1PAE3NDUYOcC7tDO0EFbhEg3Qo rs+zqu3qxxX1Y25o6T64Detj3ICs38Y/UGQiDttWY7otMoGEyOIMUVWGMzdDoHH7eczq DVoHgKEG9Mv+c4PcIrosz3VkidxfV2ERfEs4/001ZyUkV7gkW9XgPoHKYL2LfCieu2Zl W9nA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722631145; x=1723235945; 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=OaXT0AL8GbS9YXbDGbiDFqWt3txOFoZxKOINxRCY5SE=; b=a4my0kYyWtTNJ+oa81yEoD1TaMAYvy5PyuJX/pPvqw8nKJks+AT4I+Wzc9xDcEal6s /4URsqxfFleJKE3HQZ4TR2F/BnKDsoZ01kuWNX1uPZeB4mW7RAeowzCg3iJ4SdOTwY3s PKOqZyjKOW1VAY290xdNuyjffhO1rEuaORd7v3qDAaZ+hTpwalpJdaMZ6bzKzSQdlhYO 6RQkSWhf9oS7xkBp65Bs8CyI5gl0abEjEYq9pgML3QSouKYAEZZE/xuPIzlwTIRQlrHJ 9jh8XCyJfqQU5z/6uuGG6nxEiTCfOdvDKBfm161lggrCfCnsh34lRoB6pJki5vlC/Zxz Ke3w== X-Forwarded-Encrypted: i=1; AJvYcCUKLRQxkF3DGXPJ5ry89NLMazIlx17qAR2PEATabZStUfPd22y+D7PwVGkgC/C/v81xs+jCbNEcsk2VtFjJN9JMIpWJ0Ud3WlxqW0Eo X-Gm-Message-State: AOJu0Yz9zusBYcYtqbVtYb69UYXPmXhWv9s9H17rpzv/OxRnJ2JnNDnL zJp3VDGwnNFpZS67HObqpychlVKyMBO5dKGGvsRg89BZr41pNYBBynGZuwqphruubbbOM+W1/Q5 xrg== X-Google-Smtp-Source: AGHT+IHQrbolfUfTpHvOTZVD4J59z3A8mKmJAPa7A07Gpd2BgjA5jYbxRm2+aRNcTednDQCuVzY4bKyQXBU= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:902:d502:b0:1f9:b35f:a2b6 with SMTP id d9443c01a7336-1ff5725095fmr2659555ad.1.1722631144792; Fri, 02 Aug 2024 13:39:04 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 2 Aug 2024 13:38:58 -0700 In-Reply-To: <20240802203900.348808-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240802203900.348808-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240802203900.348808-2-seanjc@google.com> Subject: [PATCH 1/3] KVM: x86/mmu: Decrease indentation in logic to sync new indirect shadow page From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Combine the back-to-back if-statements for synchronizing children when linking a new indirect shadow page in order to decrease the indentation, and to make it easier to "see" the logic in its entirety. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/paging_tmpl.h | 40 ++++++++++++++++------------------ 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 69941cebb3a8..0e97e080a997 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -674,27 +674,25 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct= kvm_page_fault *fault, sp =3D kvm_mmu_get_child_sp(vcpu, it.sptep, table_gfn, false, access); =20 - if (sp !=3D ERR_PTR(-EEXIST)) { - /* - * We must synchronize the pagetable before linking it - * because the guest doesn't need to flush tlb when - * the gpte is changed from non-present to present. - * Otherwise, the guest may use the wrong mapping. - * - * For PG_LEVEL_4K, kvm_mmu_get_page() has already - * synchronized it transiently via kvm_sync_page(). - * - * For higher level pagetable, we synchronize it via - * the slower mmu_sync_children(). If it needs to - * break, some progress has been made; return - * RET_PF_RETRY and retry on the next #PF. - * KVM_REQ_MMU_SYNC is not necessary but it - * expedites the process. - */ - if (sp->unsync_children && - mmu_sync_children(vcpu, sp, false)) - return RET_PF_RETRY; - } + /* + * Synchronize the new page before linking it, as the CPU (KVM) + * is architecturally disallowed from inserting non-present + * entries into the TLB, i.e. the guest isn't required to flush + * the TLB when changing the gPTE from non-present to present. + * + * For PG_LEVEL_4K, kvm_mmu_find_shadow_page() has already + * synchronized the page via kvm_sync_page(). + * + * For higher level pages, which cannot be unsync themselves + * but can have unsync children, synchronize via the slower + * mmu_sync_children(). If KVM needs to drop mmu_lock due to + * contention or to reschedule, instruct the caller to retry + * the #PF (mmu_sync_children() ensures forward progress will + * be made). + */ + if (sp !=3D ERR_PTR(-EEXIST) && sp->unsync_children && + mmu_sync_children(vcpu, sp, false)) + return RET_PF_RETRY; =20 /* * Verify that the gpte in the page we've just write --=20 2.46.0.rc2.264.g509ed76dc8-goog From nobody Sun Feb 8 06:40:18 2026 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9D5C7770F9 for ; Fri, 2 Aug 2024 20:39:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631149; cv=none; b=NUhSd6B8avwBLgGfpGRCbqxi9E0pJw28ju7fEfIs2dMe0hz3w7BJmOva5GCfUeM1D9il4kXDfQlJZR2lkesSBuwmXjWRefYEoLKMDeKLtLvL0n1VQ4cqWK6ieIakw1a0CQ4XsgRMgOJUGS4T5UmgvAAafdNEFoHle2MDHlh2pEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631149; c=relaxed/simple; bh=wK7gvcPluzFLYAgCx110aK6DlBTtzRCvOU4RMwEP21U=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=eskHsB2J+FNMviNFGQI04anAlVBrZL9i315U4fqUdDMo1AhGoQvh8sp7go9wZxbtosWNwHu7kYviIhsj1uViFfQOICBsvp7cLxbaBbP021SqckAI0ilV/WnycORigCp6gGe8XhJX3JyKbw+yMqPvznT33/n0EzuB5CaMWhUlu3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=R+EkXq70; arc=none smtp.client-ip=209.85.216.74 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="R+EkXq70" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-2cb600e1169so8785003a91.1 for ; Fri, 02 Aug 2024 13:39:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722631147; x=1723235947; darn=vger.kernel.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=lhZfJ+eif378+aP65STvVCIFX2Uzw5vooug8NPmiLuI=; b=R+EkXq70xPxurkb69ywwZXuXnOBR2Pzj0swqypYlxehccYz4qgsFwP/YLnpjdp13KL q5dIdLMgU12U8CEvqRLqdwzHA4S9Um/0YWSP04taZZhdIFvIUauEFrOJgWu63BlgHzMG HSMIyyO1pEu5mtcygRxGuA3rmIof6Cvf5Zw5oUnawA18c+Uc1fJq9Vhw0eNhhHhwAbDo ieqJKLpfEJ2pBHZZtLfZ5jhifH8lfI2WQdvardiE1XZA/KnJTTSlMCTSiubfqsLomH4e 9EsIPiYUOxzuG+T2MdOakNpCQ+zPDO0btXvHraEMIWWJdTLboKJ40RHO55pxCRQSh/g5 Y5Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722631147; x=1723235947; 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=lhZfJ+eif378+aP65STvVCIFX2Uzw5vooug8NPmiLuI=; b=LrNTlNApoaAuUHeCpqIUcE9vDlNtJSwuw2y44VBNs8J+jr78H33uoAoWqHEZgNA08M PON+vyleTmDG0OJ+X2gCmz2ckJ3FjQK9lLmIbmXfV2BoVml+Sys++mV1TmXOipRmU1ya jBSkQ0lpZptTjWsPy0Rou/Z0HxS9CjmyB8vGiy6UxW70vfEgCECWXWmCgcwRKdDgUAg9 NmS/wQiO/7FpJ8ocraWNWYVSgTMfUaknL39/UHSVlpX3ZHBYeLlsHIWG71x4eo2JQLt2 1hwomCeb8xZM+gd7TttsLFy3CDLytl8EKhkgI5FZ2+b8F5BY7ZmuzRvhiPpKHOr067IP lvgQ== X-Forwarded-Encrypted: i=1; AJvYcCWWbUWGJEeGRiGn1aJEP/yUInPb4Fa33bxT5lKdsI8c1EMGFeTVLlGeLFtG40bqo3UculQMwvtMegurkib6G35LLLj++682OMZ5wXa9 X-Gm-Message-State: AOJu0YwwfgNDUAUUngJakeeOJcTxh9vtz+kcA5YtEYyRoyNVILgds2+6 sqcbPpM7tbfVQQN6AaCoLnAE4O7GcBtRTi9qjUTFWfBe9ubFHERQxU4MMDvVmsGp8uPwWEj2aOj tmw== X-Google-Smtp-Source: AGHT+IEBDd6K3pOLPAqR+BBCXxX6Cd9PwpLbhI/q8t6tG4WEhlza6f+vxGhPQHeXbKP6WWFy3TfBCoa51nI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90b:2305:b0:2c9:5fae:4f80 with SMTP id 98e67ed59e1d1-2cff9570addmr120536a91.8.1722631146764; Fri, 02 Aug 2024 13:39:06 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 2 Aug 2024 13:38:59 -0700 In-Reply-To: <20240802203900.348808-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240802203900.348808-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240802203900.348808-3-seanjc@google.com> Subject: [PATCH 2/3] KVM: x86/mmu: Drop pointless "return" wrapper label in FNAME(fetch) From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Drop the pointless and poorly named "out_gpte_changed" label, in FNAME(fetch), and instead return RET_PF_RETRY directly. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/paging_tmpl.h | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 0e97e080a997..480c54122991 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -646,10 +646,10 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct= kvm_page_fault *fault, * really care if it changes underneath us after this point). */ if (FNAME(gpte_changed)(vcpu, gw, top_level)) - goto out_gpte_changed; + return RET_PF_RETRY; =20 if (WARN_ON_ONCE(!VALID_PAGE(vcpu->arch.mmu->root.hpa))) - goto out_gpte_changed; + return RET_PF_RETRY; =20 /* * Load a new root and retry the faulting instruction in the extremely @@ -659,7 +659,7 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct k= vm_page_fault *fault, */ if (unlikely(kvm_mmu_is_dummy_root(vcpu->arch.mmu->root.hpa))) { kvm_make_request(KVM_REQ_MMU_FREE_OBSOLETE_ROOTS, vcpu); - goto out_gpte_changed; + return RET_PF_RETRY; } =20 for_each_shadow_entry(vcpu, fault->addr, it) { @@ -699,7 +699,7 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct k= vm_page_fault *fault, * protected is still there. */ if (FNAME(gpte_changed)(vcpu, gw, it.level - 1)) - goto out_gpte_changed; + return RET_PF_RETRY; =20 if (sp !=3D ERR_PTR(-EEXIST)) link_shadow_page(vcpu, it.sptep, sp); @@ -753,9 +753,6 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct k= vm_page_fault *fault, =20 FNAME(pte_prefetch)(vcpu, gw, it.sptep); return ret; - -out_gpte_changed: - return RET_PF_RETRY; } =20 /* --=20 2.46.0.rc2.264.g509ed76dc8-goog From nobody Sun Feb 8 06:40:18 2026 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9907B12AAFD for ; Fri, 2 Aug 2024 20:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631151; cv=none; b=nMeIzrNcHXM5DOgbr3Ri3IV8D1VRLE+o/WOqFopUW38mZ5WuYa0sOoJq2S4z2Gwz+8iosjubX3mZW2bvKMLQ0MLpgfqxpqHuvcImQ4ZHfDR/AcXTku9ydzdZKr2Rgbe10GVs/gqLFgrEgj3X7ISn9+CxxVxrfm7WR3XS0iMo0CA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631151; c=relaxed/simple; bh=ul3I8jtNfEVe2uxdPBcvEuYLJaZMuXyRTYdE99HTjQY=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=DqrH7wea2U7j1cRjQMJoyHoQs55c32A7DTeYW7zjp3BbUN94dOhFSIj6jSRs96LPm9lFhKOip65a4OklP6TfGkz/hjs3i+ZlTSLwWzVwDTJALJ3rHjdedO0areTh7mK1z34BQgI58cP/Q94nSUnehX9P+t7eivhBHx2XYi5CgzE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WSU7wFT7; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WSU7wFT7" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-66619cb2d3eso185811587b3.2 for ; Fri, 02 Aug 2024 13:39:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1722631148; x=1723235948; darn=vger.kernel.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=UjvdKHX5XmbdhKLTWlXN2ri3L77fxrqJCXnnfCjoJs8=; b=WSU7wFT7U36UARGVoVUTZUcunD+twpI4AKK76AqUPiys9it226ott+xEmVe7CHivdx IXDlp7TFucZK8OvRnzA2Vnso9wBzaHKVz1zs9LafIosw5NZ9nscV7yRcuH5FARh23VUp Jpw5CHYXpd/zzMBTBqCWWCB71g3pNixI8FpMmfXgbsjJSNPb5wuUv+bLXKjuHDUpTg81 6j14Q63GQIg53L1aka8rItRQew9p0DihLyKEn7VbTyUBMEUEk5Do+Cn0hEKyEoxz7qc0 2Ws7mVMIAI17sTSgglmTmDZUQgKYSOF5tOsofoN4+Ixob6LRIk+s6rMo+EczdQZrKUC/ XDwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722631148; x=1723235948; 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=UjvdKHX5XmbdhKLTWlXN2ri3L77fxrqJCXnnfCjoJs8=; b=U4S3s9J29PX6iZYr0RzuxdI0KeAFqLnq9SM0c6FCWeh5fbinxeTjFn43V9Qes8Tovx BjYm4Dx4MlEhuUjRm7o9zhbPFx211UGoMfVuiycrisjMSeSZTd0RjRTLRXrfHeQ/A+fN t1y6Dy0QJQS7gO52bl5LNXa2aVLJBomdEu7kCpgp21B/YlONJuIYybaKoCj10R8ABrxz 9RYD/1+Sb29tQlHdiZdTuJtnt5CFOrMPvKTQkoiwPisbJEypq4cIEAnNgJXpMKKz0lYR V8LmQc+iLyEuxSf3E/UFOxwDhIEGk0RI0R12gDoy6w9rp+IXcfkM4EdYBNvE7Udi+lXB rpmw== X-Forwarded-Encrypted: i=1; AJvYcCV+n087gx+j0qMX5xbqG3kf+MLa59h1PFGk4slYuDCy8VmL1I2T9Wg5pweqy1qJ4H9j9IM2QoV43rC9UmIgTXAziq0eh5GehUDIPpye X-Gm-Message-State: AOJu0YyoU3FzgVMyJqXyQOlAgzNe8sycH0zNhRnky7iXsfPCRTkKkHT+ kp+VnjQCusrVxgOk7pVMecD99IriP1Ol/WkvlF+W1aDxO6pBi/yDrWiVDrmj0zb2Zr/jaje1XzJ QLQ== X-Google-Smtp-Source: AGHT+IEPSQRTx7gBHRSttp+7gITI0epwEssMzt1KPQLzKi+lHEKLoj+vlFZlHc60M8o1PIdYF4z2PAULIsM= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:690c:10:b0:64a:8aec:617c with SMTP id 00721157ae682-68959efadcfmr3215337b3.0.1722631148748; Fri, 02 Aug 2024 13:39:08 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 2 Aug 2024 13:39:00 -0700 In-Reply-To: <20240802203900.348808-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240802203900.348808-1-seanjc@google.com> X-Mailer: git-send-email 2.46.0.rc2.264.g509ed76dc8-goog Message-ID: <20240802203900.348808-4-seanjc@google.com> Subject: [PATCH 3/3] KVM: x86/mmu: Reword a misleading comment about checking gpte_changed() From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Rewrite the comment in FNAME(fetch) to explain why KVM needs to check that the gPTE is still fresh before continuing the shadow page walk, even if KVM already has a linked shadow page for the gPTE in question. No functional change intended. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/paging_tmpl.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/paging_tmpl.h b/arch/x86/kvm/mmu/paging_tmpl.h index 480c54122991..405bd7ceee2a 100644 --- a/arch/x86/kvm/mmu/paging_tmpl.h +++ b/arch/x86/kvm/mmu/paging_tmpl.h @@ -695,8 +695,14 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct = kvm_page_fault *fault, return RET_PF_RETRY; =20 /* - * Verify that the gpte in the page we've just write - * protected is still there. + * Verify that the gpte in the page, which is now either + * write-protected or unsync, wasn't modified between the fault + * and acquiring mmu_lock. This needs to be done even when + * reusing an existing shadow page to ensure the information + * gathered by the walker matches the information stored in the + * shadow page (which could have been modified by a different + * vCPU even if the page was already linked). Holding mmu_lock + * prevents the shadow page from changing after this point. */ if (FNAME(gpte_changed)(vcpu, gw, it.level - 1)) return RET_PF_RETRY; --=20 2.46.0.rc2.264.g509ed76dc8-goog