From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CA8613C061F for ; Tue, 5 May 2026 19:52:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778010771; cv=none; b=PjA1dkzmPtkUcndFw2rLkVcLBNNQpkb0hVAXHgygNbZBKX19AjlZIY8+XDa0m0ikEBYrlCa/rFOnU5yg8lVL1K8wKNIBzhQ2qsiKiQvwRTAC0ARQ1APP2L0gkNY3//0tA2zIIOOif2n/mE20In2g7QI5mDveWiLYAVx4ourg6jU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778010771; c=relaxed/simple; bh=6KNQirbx2Vihou6DaVeh7jHQnbN8YaGebFopG1grF8I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dgXaanJV95tDr2X1UjcG9tUtiKAsYIbgMUIXnzx1lVAY+2x6sZB9oalsKYa9s8F7TjzXdAS6hj1h405EHqy3nl/JSqCxrx1PqPHTsIltsiSSB40kgu9JLAKIU2KQ2Wvwl6FDo6gvt5ABA0c/cJnQCNVsgvbdDhKgfmoD4xVkRWc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=H4LS8Qs0; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=C0CeIc2G; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H4LS8Qs0"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="C0CeIc2G" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1778010766; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=9PYNfAaEV38buKctZeF6dh10BP+mDAO9Hnu887EwhKQ=; b=H4LS8Qs0wVjtQcq0eubzdRu8NuPqmsi/bqgXAcJtf3+uddRidOZ10Ak51dE6wrL2i4ruFj Jmlkau2IZ8vzEczUZPaNO47kvkku1sE0oincBKRJ4rjj008nn5SOfwBkENhEbijEMqYNFz sKWifClxkFtkbriWoXfCmO2wtFY+9sI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-630-FGXBNvtpOuWOhIhEhAULcQ-1; Tue, 05 May 2026 15:52:45 -0400 X-MC-Unique: FGXBNvtpOuWOhIhEhAULcQ-1 X-Mimecast-MFC-AGG-ID: FGXBNvtpOuWOhIhEhAULcQ_1778010764 Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-43d789cebcfso121540f8f.1 for ; Tue, 05 May 2026 12:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1778010764; x=1778615564; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9PYNfAaEV38buKctZeF6dh10BP+mDAO9Hnu887EwhKQ=; b=C0CeIc2G33zxtmldOXlZAMniqeTCWxhX6SppB9SXw2BUZ1pE39UypxnhFZYhewcNeM HJk9Aik+ZPNdUmuy9Rx5r6Arn/Lp1JiXSitm51u4XCdtHduATKZRWdWJpCAlazGgxhl1 C0tg8dHRln1r6eUqyKF1Pv8Z/DUOQJXTP3x4Vu0xF6FREPFrzzppkdzELr1pYZGi1Bi0 5bwlc9xlHRVZf5hfATBCKjcQGJrpCPACKcCLkEz5kanCzekuPrZzlRGuB2VC9BbTpN8u HvW3CshSzKCJPHkQoPDKOny+TntmBfgxdlgmvCKmVFPFvmkAtDMt2QOYNKYJ5Y2TqLJK xr7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778010764; x=1778615564; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=9PYNfAaEV38buKctZeF6dh10BP+mDAO9Hnu887EwhKQ=; b=iZn9LFcBExWR/fcfQWDViyezlpFV9vQ81P8k2AhzhUp0npml5g/xd0Q2p2tnVBLTJy 2yEIH7zDKhdJ1VoN5MRchhqBrLMyb9uJdPyGfz/ujGpeV2hIR2fvtZzfJ9U/ueaaLe0k n6fYOlYL/ymRJy9GzmWesffr5u/py++39AOeQ+/3GCTI7bdlCFmPc+KqCLMFlCSl+Vsf gyTMAmZZMBuJSvYpq1BPveYcJer6PhrZG3s7Bj3fDMErxHDCiL703rWc4i8htuosPLgE 5C4f3fZbNRkeZRtQesMU9LQmCCQQjVDrwj+99GM01UDJJQnVw+0Rakfa0mbJHqrMBdz9 SeKQ== X-Gm-Message-State: AOJu0Yze2OP287jR9cmckXEUdgmb37uBvjGuQ0Np5YNQe7/XN/+eWeF0 y5jheap8lohe9hUriZhMAPYgDrlBN3b7S/4EYnJJgdT9iMKHF8+N1kACwscINaEqT25M2yB543T 6tLVmkCaLH7bJsrieF8wWqFn1cSUc/GS1GIaOhlgMVRTNU8U/x9hRWGzULNa+P+jqOKHnXZV6y3 Ns9y/cqEe6nQqt3jrixOtz7KvK6CJbm4tys+AJZYNNuuEcliv3vw== X-Gm-Gg: AeBDiesAb9Mq26rWS0Cr5YubVGhoQylI3XVTagk+yqefdQrfYLdCX/rbhFFru/TX/GJ n8PHrMERN+3xJFuOHUWBYwRvnC2YaqeMDa9NPgvuTKtqmJw0qGAJkaFPZCXjxkjVnVPIv/2rmup RUsKsK16U732A/uQ47uhZJ0F1PiQbNkmnaDTk79sOV2eh1fS973ySAoh9QLZYCiMC7SGpSSNnOA OSfs3MaeL4yu6hXhXTaPpmsL52ug9AQCj5BVjuHqGyxM5BNvpzTal63WzyhN4ohAmEARiG7GoKq um//X/UEh3zunxhnhhWcYjIzeJqyA5cwckkj1FWpYpCZ0ryQTHCCPfbAkAiCKnXDKOXzYRVFaaw gRg0uIRQZ5UVqY7V9SsC6cfOAyL0BMA8/JPpyhjWrVwZwo+s8OzIPsR26fZjCWR2EJzckSPDugg asup32vC1dPpqrBLdZTuTr98chtL66PZ4toA2wehI= X-Received: by 2002:a05:600c:14c2:b0:48a:65ab:8059 with SMTP id 5b1f17b1804b1-48d142725a6mr61497135e9.13.1778010763715; Tue, 05 May 2026 12:52:43 -0700 (PDT) X-Received: by 2002:a05:600c:14c2:b0:48a:65ab:8059 with SMTP id 5b1f17b1804b1-48d142725a6mr61496915e9.13.1778010763358; Tue, 05 May 2026 12:52:43 -0700 (PDT) Received: from [192.168.10.48] ([176.206.106.181]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4505238e7c0sm6115716f8f.3.2026.05.05.12.52.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 May 2026 12:52:42 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: d.riley@proxmox.com, jon@nutanix.com Subject: [PATCH 06/28] KVM: x86/mmu: merge make_spte_{non,}executable Date: Tue, 5 May 2026 21:52:04 +0200 Message-ID: <20260505195226.563317-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260505195226.563317-1-pbonzini@redhat.com> References: <20260505195226.563317-1-pbonzini@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit As the logic will become more complicated with the introduction of MBEC, at least write it only once. Tested-by: David Riley Signed-off-by: Paolo Bonzini --- arch/x86/kvm/mmu/spte.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/arch/x86/kvm/mmu/spte.c b/arch/x86/kvm/mmu/spte.c index 85a0473809b0..849a1c1c92b5 100644 --- a/arch/x86/kvm/mmu/spte.c +++ b/arch/x86/kvm/mmu/spte.c @@ -317,14 +317,16 @@ static u64 modify_spte_protections(u64 spte, u64 set, u64 clear) return spte; } -static u64 make_spte_executable(u64 spte) +static u64 change_spte_executable(u64 spte, u8 access) { - return modify_spte_protections(spte, shadow_x_mask, shadow_nx_mask); -} + u64 set, clear; -static u64 make_spte_nonexecutable(u64 spte) -{ - return modify_spte_protections(spte, shadow_nx_mask, shadow_x_mask); + if (access & ACC_EXEC_MASK) + set = shadow_x_mask; + else + set = shadow_nx_mask; + clear = set ^ (shadow_nx_mask | shadow_x_mask); + return modify_spte_protections(spte, set, clear); } /* @@ -356,8 +358,8 @@ u64 make_small_spte(struct kvm *kvm, u64 huge_spte, * the page executable as the NX hugepage mitigation no longer * applies. */ - if ((role.access & ACC_EXEC_MASK) && is_nx_huge_page_enabled(kvm)) - child_spte = make_spte_executable(child_spte); + if (is_nx_huge_page_enabled(kvm)) + child_spte = change_spte_executable(child_spte, role.access); } return child_spte; @@ -379,7 +381,7 @@ u64 make_huge_spte(struct kvm *kvm, u64 small_spte, int level) huge_spte &= KVM_HPAGE_MASK(level) | ~PAGE_MASK; if (is_nx_huge_page_enabled(kvm)) - huge_spte = make_spte_nonexecutable(huge_spte); + huge_spte = change_spte_executable(huge_spte, 0); return huge_spte; } -- 2.54.0