From nobody Thu Apr 2 20:14:49 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 3B53D3A5E6C for ; Thu, 26 Mar 2026 18:17:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774549068; cv=none; b=AruEETm+pCxph1O/gLblnv5X010bEqLsi1pGEfQSYpOJkYCoIMqLlG2iyupqkaRiGVpQqKaKQUniiHyIl/CEGCsJRMnNMjrtpH6OwUQ6lu7Lx798c3RIT5Y7gpFkiGdkD3Q+7GoHFfHn1BKFT6NQGUugBXjThitu3M6TNsXBXXA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774549068; c=relaxed/simple; bh=C3056jeL2T8VZuCnAsJAFXdeOS+u5HTlm+hZkzVz0xw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UEcBThUkBBEo6ArCoKpEr+cc28MkgQck+dKSfQJdXnJ4AaU5umhLQrY2Be90ZyQ01RdpuCg/Lysl7LunT76GXFThj1sUPms6aLEoAImZcOeYOZJ7q8+g7jide7emwpSIav8jvYoQ8IvtJDACAZcVAJuZvVns8DgRpSoz4zbVygs= 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=DLhkZrYV; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=I1qcyjcR; arc=none smtp.client-ip=170.10.129.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="DLhkZrYV"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="I1qcyjcR" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1774549064; 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=U1aF2Xc1/2U0HH4M9V6/k6D1Qk02VU2RtFjLbY3oaWo=; b=DLhkZrYVzFN7FCPVY7arXS43Yt2Sit9oQ5HANuOMCcIXmNwowk9lQyrk/TrKCfJg3+SfCN IQgjgm9IClfEyDh83V0lzm3ZR/fxePGetBjyXQSo0GfqBeQTq85PWaNBzd6AQs/mzYIzDo 2bGzdpswOx8LqomxfcqXYGZq9wCDVUg= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-205-Lda1gOZWP-WebV-pO7Zv-A-1; Thu, 26 Mar 2026 14:17:43 -0400 X-MC-Unique: Lda1gOZWP-WebV-pO7Zv-A-1 X-Mimecast-MFC-AGG-ID: Lda1gOZWP-WebV-pO7Zv-A_1774549062 Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-48535f4d5e1so16565345e9.0 for ; Thu, 26 Mar 2026 11:17:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1774549062; x=1775153862; 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=U1aF2Xc1/2U0HH4M9V6/k6D1Qk02VU2RtFjLbY3oaWo=; b=I1qcyjcRLlMoRW/Xfzzch6JWpeA0ljlVgGIRNKosqyfdpw5I+ExD2XR2q4nRLgvN58 AiS7DbzRxes+AH1oqWjk9PtuIxPwK4Cc2dkrp92xLjOjEgWHl1aM/+Go6RppDfqfITb9 r5LbCbuYhyRr3iZA9L1xVO48irUK6PxbE7ZCvqTxJdHqWWe4Js+A3oym3otbDpWUgSSV j8SarEO4+OofAn+7sx5VviPDTzUr7iRJz5Y8toXNBcgCHDnJHPIz9LUuGJsDhcDXmO/C Ncf9TP7UcMY0SWRMx9VmoFbzS/wt3FoMVMc54Ouor0fYpCcTKE5I3whUuWngDldf3YI7 UcNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774549062; x=1775153862; 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=U1aF2Xc1/2U0HH4M9V6/k6D1Qk02VU2RtFjLbY3oaWo=; b=LkAW5F4p0USYr3w3ojngY6bvYYlI7/mJ0YMLD6MalSChRo4us1+VHk+rPrPyM8WZ4S ZUIOFmhhknMfEnSVeneYSRFTozL1BaDluv99Oh/QQJ/i+JSKMvTZ87Hrqme4PQh0mh5N pzdTE2uuTP3ZjoujDpUxddeAqXNN+Y/VYDmiYbHnvj84ia5K+T4uSYiXLn9OTQUHClVP myGL8vRM3v2D54GVHNOiBkXcorh/c877Zqgl2bB/rQ1ceBQY1QSh6/DSOIbHM+IFtjWc dgdSgv1uuxPszOym3npbRc1EUbzEGGKvsejutxytgXNJX5hGYIVluV++G2/0FcotpcNd bKEg== X-Gm-Message-State: AOJu0Yws0nZPrp9VR6rFmm7J44Tsz+I9dM/BL9TrAIK9UbB+vW8t3JIU s76JrjkPvoK3mj1liY5QTN5X+I2I2X2KhRht5CBjBx0C0Ma6yEzZuHtEMyHT+mhMzxxevcjPpcJ dO6rv/VNOBvIbYN4cBkqn/tPA2pkhSVhnGSwB1Hh/NQjGEFoLhYJcrtoAN42lkilPBor0VCrRA8 6C5ejGik/duYycZTR6bcYGnamOUfjXzyK1kuhdSQ2XA3UA7Q3hMw== X-Gm-Gg: ATEYQzzuQRXxiDTwsQbncM6qIdKYB5KTUQy/2y87Rr6/aNExfQvzzdVvxBdz6vhDz5/ EkS3DDEcnXyqpulo1bo5i1bLDw/jt1xTKus3cDxBJHXSoC+x4itkPZMjnr/g8cAsjP9uE/t1GJ7 jmvlUbFfrl7I+3zjZfbyEDPAV7wtiJB7CIgk9QBIqprGj5oObbJN/TcQOBRJ9pNW5VPZ4HGLTs7 RF3uuEPGx1HuI/NM3VccV/891ntO1ttIPwiew6BARrdtHqt6+N7nbuzWVAiocRA6iXXGTr2q8A5 WEvBWGUXNa8L1+Ip5tn40fthh1RaaJX7k3vlxP9QWih+UJoq12LzZxQC8TshI/hwda7SfRIWXSB Yy5RFo96nRwbL72UybAG3Ll0HINsvFNKFZZiSbawfoCF507lTDujKv3rMHqJGiuSWBD9H1rmHSJ kTnsNfmJBh9s1Tkfu1s8JMg8yn X-Received: by 2002:a05:600c:a408:b0:485:3f58:d9f with SMTP id 5b1f17b1804b1-487160a24e2mr98477155e9.30.1774549061913; Thu, 26 Mar 2026 11:17:41 -0700 (PDT) X-Received: by 2002:a05:600c:a408:b0:485:3f58:d9f with SMTP id 5b1f17b1804b1-487160a24e2mr98476755e9.30.1774549061407; Thu, 26 Mar 2026 11:17:41 -0700 (PDT) Received: from [192.168.10.48] ([151.49.85.67]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48722c9f58fsm75854345e9.11.2026.03.26.11.17.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Mar 2026 11:17:39 -0700 (PDT) From: Paolo Bonzini To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Jon Kohler , Nikunj A Dadhania , Amit Shah , Sean Christopherson , Marcelo Tosatti Subject: [PATCH 06/24] KVM: x86/mmu: merge make_spte_{non,}executable Date: Thu, 26 Mar 2026 19:17:04 +0100 Message-ID: <20260326181723.218115-7-pbonzini@redhat.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260326181723.218115-1-pbonzini@redhat.com> References: <20260326181723.218115-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: quoted-printable Content-Type: text/plain; charset="utf-8" As the logic will become more complicated with the introduction of MBEC, at least write it only once. 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..e9dc0ae44274 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; } =20 -static u64 make_spte_executable(u64 spte) +static u64 make_spte_executable(u64 spte, u8 access) { - return modify_spte_protections(spte, shadow_x_mask, shadow_nx_mask); -} + u64 set, clear; =20 -static u64 make_spte_nonexecutable(u64 spte) -{ - return modify_spte_protections(spte, shadow_nx_mask, shadow_x_mask); + if (access & ACC_EXEC_MASK) + set =3D shadow_x_mask; + else + set =3D shadow_nx_mask; + clear =3D set ^ (shadow_nx_mask | shadow_x_mask); + return modify_spte_protections(spte, set, clear); } =20 /* @@ -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 =3D make_spte_executable(child_spte); + if (is_nx_huge_page_enabled(kvm)) + child_spte =3D make_spte_executable(child_spte, role.access); } =20 return child_spte; @@ -379,7 +381,7 @@ u64 make_huge_spte(struct kvm *kvm, u64 small_spte, int= level) huge_spte &=3D KVM_HPAGE_MASK(level) | ~PAGE_MASK; =20 if (is_nx_huge_page_enabled(kvm)) - huge_spte =3D make_spte_nonexecutable(huge_spte); + huge_spte =3D make_spte_executable(huge_spte, 0); =20 return huge_spte; } --=20 2.53.0