From patchwork Fri Aug 2 20:38:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13751975 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 BC5F956440 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-1fc4e03a885so74870565ad.2 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=MYyLCWgzZiZOtnMLVPN22HPFX9ptiNn3D2yYsVRBMzdPclmdFZkVhqKI+AD2mBN9oA vq1bbJSo9ZacKg/j5N9bhOnapGgyFoim7OzU6eE/Z0Nt/1dHksjD3KKlpSM0xTehqWMK EA7kFcmT+ikHfR+0RKMR7aVYZkm5SasSj8CXSeBPvl6+uhU9s26WpyJsqdo8Wsz428sZ AiCnEWm5KP+/UUkvEiZz2FbmMxSR6eo8kH6UdFgN+aakXcnegLURhmiuWupAUkEQsz3+ aWUrvnrQRDPSqRfEP4L/Xmo8CikKJ198GDCtAtCtpedwUnOOtfJR/Oeo/LhZX2DDA05k QiJg== X-Gm-Message-State: AOJu0YznmCUSH06UpJ7D8A3aCw3vAvgdGFp4JoLEQwicx4E1dHga4WDJ 1YrcHPQzgREP2Zo5RFwSXiLjQftkTakmZSITC9tnJOkEPsYzUO4BjR4jm6vwlLjnChK27wkLlf7 AJQ== 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: kvm@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 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 = kvm_mmu_get_child_sp(vcpu, it.sptep, table_gfn, false, access); - if (sp != 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 != ERR_PTR(-EEXIST) && sp->unsync_children && + mmu_sync_children(vcpu, sp, false)) + return RET_PF_RETRY; /* * Verify that the gpte in the page we've just write From patchwork Fri Aug 2 20:38:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13751976 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 975DC763F8 for ; Fri, 2 Aug 2024 20:39:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722631149; cv=none; b=X7WiF+K4LtN/KIYQMi6ZcsAo97GBgt10plJKpuD4ww1h/scMITWBmOPRrML9muynJAkDRnjIyWJkS0LgtM0qUfGQWC1J9cIkAZy+BuvSDKS/NaaxTVHi8BXDkYc/LO9vmLj14HcB+oClB/TL8lxk9sRV/YNQw4bwA7iep5f+4WI= 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.73 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-f73.google.com with SMTP id 98e67ed59e1d1-2cb696be198so8773111a91.3 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=T9qam6FjzAr6CHC+Qv35jUdXZD9TrXeoeEOJo4M6nePm+G9M9HLos2xyAz/KNZvY0T d6pnyDoWGx3ThXcqyYMsI0+5vZdxYB3BlqbYoCix0QiMwL4cu5A0Dxfe69viDqoABqIb /7ukv8iIFR7QrCcn76+4/bNqsr0maGs6vae2xblgGVijACxY7hrijXonJf1lO1HzUUJ2 5TIw5CpCZ10Oi2uv1dnEGWk4HIuNglhdXjOO8Wz4bS5tc9R79Vw1q1rALIbTNjZirY7n tUA2PPwog19ZNB4CTo/QPwjUxO8B1udUOBG/Q2N/5zMgFKJw87tdG+1tfeI8Fp6G7P/u tQeQ== X-Gm-Message-State: AOJu0YzTjgbXJnD8PEPmD40DfHFp1A/IADBgBGyyJi4z/CxjKR7IAnze oZGjAF0tpkpsRK69PbAHz2fvynsL1eU/MRVNH2vMTGdqXsLJZ04fEy64ipd7N/xfY23KXVtQyL1 D9Q== 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: kvm@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 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; if (WARN_ON_ONCE(!VALID_PAGE(vcpu->arch.mmu->root.hpa))) - goto out_gpte_changed; + return RET_PF_RETRY; /* * 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 kvm_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; } for_each_shadow_entry(vcpu, fault->addr, it) { @@ -699,7 +699,7 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, * protected is still there. */ if (FNAME(gpte_changed)(vcpu, gw, it.level - 1)) - goto out_gpte_changed; + return RET_PF_RETRY; if (sp != ERR_PTR(-EEXIST)) link_shadow_page(vcpu, it.sptep, sp); @@ -753,9 +753,6 @@ static int FNAME(fetch)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, FNAME(pte_prefetch)(vcpu, gw, it.sptep); return ret; - -out_gpte_changed: - return RET_PF_RETRY; } /* From patchwork Fri Aug 2 20:39:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 13751977 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 9903912AAE2 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-664fc7c4e51so165288437b3.3 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=1722631149; x=1723235949; 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=SyH5lq76aEEl38TvBxkFUc7DD64HEDV+TFYbRNkyVqa1pGlBpxkChVfsSQTmaDlrn+ 8SmJoWa6IFMS1U1ETT8x2w90lYIrC8X4KIOyRFCrNglf66rvXdpgtqDGcnwxPaZIgIJb Mf2gAvQPBAktcnF7WxWYWrdLZy0D2PqYA00XT9xT+/44qDnjQiWjtnxGTPXRQnHZXBqM m1hibvwpvZL0+E/0x3AU1pwNNvfX7BJI9TlVUsmeoTc6DMxldvFn+EdrLqEinqSXLtZu kx6cVVyMK/yGq8Rz/ttpeBXG80Yp2Q6sfSTslhw81K2MMG1LYgwD049r66krMMvuZHPx l/og== X-Gm-Message-State: AOJu0YzIYQYTID+wY9/nL9pldCSTzqN78TRm/+s3HTTH9ds9pb6isX7d FjnhMuhMnCMZSLPLYDb/0LTkTlrfEw2Tc572yfpL92yRpG0RwpoFUIHu6eEwecArfSd2m5eYy64 07Q== 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: kvm@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 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; /* - * 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;