From nobody Tue Nov 26 07:53:10 2024 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) (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 CED321FB3E9 for ; Fri, 11 Oct 2024 02:11:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728612690; cv=none; b=UN2xexLJHQqD49wxTpBzW91bKJh46dGGpeomUWsq25+wYRDTRcr8MhKsG2fpIDruejxaDzwuHfzRw3ULZ8QnmMB9KkE4qiGImv/PtwfUajBTF9DaWuJ2qv2dkZCedQWqiJgEwlCTZKhNCj9ieRGkSmcv8Zgd7eIXhJi2bwcTSpo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728612690; c=relaxed/simple; bh=Tp2aWz/KUkLgHNMUQeB0T53YK5NkYJtBqImftywh1pg=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CE5eSORFRWGikF+B1iwIAdzOGEA0mMGmR5D0aPzGiSf/jxB6EE3uFmXzA5+JHHvgGOzgPCpByuYebg/cMV6GZANrEbbeza0DWMuZFfZwqEOEsdUAVzm4dNLHtR7Th3KdMDnwQALgNDceURdIWRTcheKuTrwOf4+HW30Vf1r507M= 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=Va1ihGKY; arc=none smtp.client-ip=209.85.128.201 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="Va1ihGKY" Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-6dbbeee08f0so39660707b3.0 for ; Thu, 10 Oct 2024 19:11:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1728612687; x=1729217487; 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=VgP7ZnqG8N9jdCaiPxtHytdx2vM8g+9dqJnt13kkQQE=; b=Va1ihGKY/nVmOINfhOXd8M7aT59KbsX96wpgdbJhNOvasLR7rfi4cXKK897pDwFb9U 06n2x/k5uhzaF1eHKcISXMkmp3ANm7qFdyOqtzNdf8oosPh+ZvIyi7wp5lOCpnuDYqrx EJtcBckCfISE54OIGSKBr5PGTshjngSM9e8ziO4yH5yVBaD8Z8stDD5QiWaOR+jTVvUJ T8xpaVusrO/uSap8jQ+Lv6oPyhLNNOCl3kw3zb4lpGBjSxwFRzd+2IJdaa3/Jat6O2Ve ATqFKi9KPGR5JmYDOl7qlmyMXf7k0YxYPxWXIgKVRFFkwb0XeeoGduKPTdLlm7gkjp8c Ck1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728612687; x=1729217487; 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=VgP7ZnqG8N9jdCaiPxtHytdx2vM8g+9dqJnt13kkQQE=; b=Kb8GgAbrzLFE/qIdqMtv3zoDku8xHBXJRVrPY6s35p5YcqzxFTdMY20/QU+/NlZcH5 dXwYRndVtkjGJ53b1+hcEW/4yz+Sa2O+ei0YgX0lZfxO7Q9NoHiNiohTYYn4/qoC/kqU guceYmKUrm8Vck2/n1Yyf1IGZRzv30Rm7BTSmQaS+bs0R+vL0CuhzwJYD3PbMEhj4VAv 1FFi/01Hi4HA5CPCHZEUgbYdzmrInXUQKCUIkiXfn3kKxpd648lT+2akppYlFbuvuQRM 4FyQsszPNEcoM9sjW84gDGn8dCXLr9wXddNVNwTZFO/raq6aPc37SvQK+eWLHeTeGeX2 75lw== X-Forwarded-Encrypted: i=1; AJvYcCUKNLtpKuG1LZ2H94b5PBaMQ857/shElNlS22PwvTOE2c+UyNDaaO5LiWl/lsuVwjayV5fcHTPZdoP2HmY=@vger.kernel.org X-Gm-Message-State: AOJu0YwHiFyvRKOOcwFC96yQqf5EojwmrnV1RwEh+73YB61m3gM2mVWO H6iptLP7UUynwKjZf6+07jhv9o7phnPhS2vTDnu97E1bcIIi2/Nr4lWybinq2ctnXSYMY0Sx2vY MTA== X-Google-Smtp-Source: AGHT+IHfuBbi88SzKZ8fyOpKZIpd/P6uL6w934+Qz4f2IixKQEh8/8BEdcKQO7aaLExUXEvNpT4HwLrwVCw= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:9d:3983:ac13:c240]) (user=seanjc job=sendgmr) by 2002:a25:b104:0:b0:e29:a86:fd0d with SMTP id 3f1490d57ef6-e290bb40627mr81586276.5.1728612686619; Thu, 10 Oct 2024 19:11:26 -0700 (PDT) Reply-To: Sean Christopherson Date: Thu, 10 Oct 2024 19:10:48 -0700 In-Reply-To: <20241011021051.1557902-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: <20241011021051.1557902-1-seanjc@google.com> X-Mailer: git-send-email 2.47.0.rc1.288.g06298d1525-goog Message-ID: <20241011021051.1557902-17-seanjc@google.com> Subject: [PATCH 16/18] KVM: x86/mmu: Set Dirty bit for new SPTEs, even if _hardware_ A/D bits are disabled From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yan Zhao , Sagi Shahar , "=?UTF-8?q?Alex=20Benn=C3=A9e?=" , David Matlack , James Houghton Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When making a SPTE, set the Dirty bit in the SPTE as appropriate, even if hardware A/D bits are disabled. Only EPT allows A/D bits to be disabled, and for EPT, the bits are software-available (ignored by hardware) when A/D bits are disabled, i.e. it is perfectly legal for KVM to use the Dirty to track dirty pages in software. Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/spte.c | 2 +- arch/x86/kvm/mmu/spte.h | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 617479efd127..fd8c3c92ade0 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -237,7 +237,7 @@ bool make_spte(struct kvm_vcpu *vcpu, struct kvm_mmu_pa= ge *sp, wrprot =3D true; else spte |=3D PT_WRITABLE_MASK | shadow_mmu_writable_mask | - spte_shadow_dirty_mask(spte); + shadow_dirty_mask; } =20 if (prefetch && !synchronizing) diff --git a/arch/x86/kvm/mmu/spte.h b/arch/x86/kvm/mmu/spte.h index a404279ba731..e90cc401c168 100644 --- a/arch/x86/kvm/mmu/spte.h +++ b/arch/x86/kvm/mmu/spte.h @@ -316,12 +316,6 @@ static inline bool spte_ad_need_write_protect(u64 spte) return (spte & SPTE_TDP_AD_MASK) !=3D SPTE_TDP_AD_ENABLED; } =20 -static inline u64 spte_shadow_dirty_mask(u64 spte) -{ - KVM_MMU_WARN_ON(!is_shadow_present_pte(spte)); - return spte_ad_enabled(spte) ? shadow_dirty_mask : 0; -} - static inline bool is_access_track_spte(u64 spte) { return !spte_ad_enabled(spte) && (spte & shadow_acc_track_mask) =3D=3D 0; --=20 2.47.0.rc1.288.g06298d1525-goog