From nobody Wed Oct 8 08:14:20 2025 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.10]) (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 889BA26FA59; Tue, 1 Jul 2025 09:59:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.10 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751363948; cv=none; b=a863aFmyy5bG+s6joJqfmJ4PewOf+OPHV3YHmROY8zzLxNRJ7hjqQZJzmRhV79IFGb5/FFBZt+Ypms9uNe8L+HlHp8cd3E5Fj/vA/4pqgQSDuZBVz27YILW93Cvhvn/venlg4paxpnkL7CT+g+wU7djY2gtoG5SxZgdB6QAXn9k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1751363948; c=relaxed/simple; bh=TQ5RCfOQ/5tuZqESL8hi2WCyzYpg/ALQ/w3Eenbo4Ow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BUJuMGn7HEeBj8ecycG2FtSCBAtAdGCSbZsIaCHg5d2q3gAgozF+tMukD9ahYkgh+kjxG07hAGBSs/0tgbVa8zT1eFrcPIvW7F6/BWh2ECRLH4ld/15ndHG9X7xMDqYwKXuc0mVThaVYuY1hS98pN0DbWOwJ4Ug+dR9d1pF5SgU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.helo=mgamail.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=WhJDZRRT; arc=none smtp.client-ip=198.175.65.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.helo=mgamail.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="WhJDZRRT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1751363947; x=1782899947; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=TQ5RCfOQ/5tuZqESL8hi2WCyzYpg/ALQ/w3Eenbo4Ow=; b=WhJDZRRTqqAbzW/GY3lIx0eFqekyRkc7f/JOlzhxuEKS/pBWqqUY2MUM V0pwiJNxmgTd1bXYjVvzhJo2K3xLZAspm0TikqfEfUpFuuuk0WeT4eYfH P5qsGjN8svtRHitVcStkccIH/MZDg7aAA3CqKya6Aa2FT0PixbAWfJuj7 q4Qcop9rbpsJvf2THrXALhC8FigX/5eNLtCGaz5Dir7E05Ju631gttaRY 5k1VYUvq6ftM6rdPiZPm6wn58ZQ6gyeShJZL94hS3HGULfLdSw+2b6Hkl iD65z8WvuCDjxWb4+8XFoKqVUEKm5rLmMtrhICaLV3CHyiGG2c4VRHMSM A==; X-CSE-ConnectionGUID: So6E2Nw/TnyAQQ+27VsnEA== X-CSE-MsgGUID: HeZ5O2Q4StasPOcy0F+trA== X-IronPort-AV: E=McAfee;i="6800,10657,11480"; a="71048649" X-IronPort-AV: E=Sophos;i="6.16,279,1744095600"; d="scan'208";a="71048649" Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orvoesa102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Jul 2025 02:59:07 -0700 X-CSE-ConnectionGUID: ulSrwC4NR46aDPQOLhrZ5Q== X-CSE-MsgGUID: kv43OEAgSp+0GwwuAzuZkw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.16,279,1744095600"; d="scan'208";a="177390811" Received: from black.fi.intel.com ([10.237.72.28]) by fmviesa002.fm.intel.com with ESMTP; 01 Jul 2025 02:58:55 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 744944B1; Tue, 01 Jul 2025 12:58:50 +0300 (EEST) From: "Kirill A. Shutemov" To: Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Peter Zijlstra , Ard Biesheuvel , "Paul E. McKenney" , Josh Poimboeuf , Xiongwei Song , Xin Li , "Mike Rapoport (IBM)" , Brijesh Singh , Michael Roth , Tony Luck , Alexey Kardashevskiy , Alexander Shishkin Cc: Jonathan Corbet , Sohil Mehta , Ingo Molnar , Pawan Gupta , Daniel Sneddon , Kai Huang , Sandipan Das , Breno Leitao , Rick Edgecombe , Alexei Starovoitov , Hou Tao , Juergen Gross , Vegard Nossum , Kees Cook , Eric Biggers , Jason Gunthorpe , "Masami Hiramatsu (Google)" , Andrew Morton , Luis Chamberlain , Yuntao Wang , Rasmus Villemoes , Christophe Leroy , Tejun Heo , Changbin Du , Huang Shijie , Geert Uytterhoeven , Namhyung Kim , Arnaldo Carvalho de Melo , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org, linux-mm@kvack.org, "Kirill A. Shutemov" Subject: [PATCHv8 06/17] x86/vsyscall: Do not require X86_PF_INSTR to emulate vsyscall Date: Tue, 1 Jul 2025 12:58:35 +0300 Message-ID: <20250701095849.2360685-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250701095849.2360685-1-kirill.shutemov@linux.intel.com> References: <20250701095849.2360685-1-kirill.shutemov@linux.intel.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" emulate_vsyscall() expects to see X86_PF_INSTR in PFEC on a vsyscall page fault, but the CPU does not report X86_PF_INSTR if neither X86_FEATURE_NX nor X86_FEATURE_SMEP are enabled. X86_FEATURE_NX should be enabled on nearly all 64-bit CPUs, except for early P4 processors that did not support this feature. Instead of explicitly checking for X86_PF_INSTR, compare the fault address against RIP. On machines with X86_FEATURE_NX enabled, issue a warning if RIP is equal to fault address but X86_PF_INSTR is absent. Originally-by: Dave Hansen Link: https://lore.kernel.org/all/bd81a98b-f8d4-4304-ac55-d4151a1a77ab@inte= l.com Signed-off-by: Kirill A. Shutemov Reported-by: Andrew Cooper Reviewed-by: Andrew Cooper --- arch/x86/entry/vsyscall/vsyscall_64.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/arch/x86/entry/vsyscall/vsyscall_64.c b/arch/x86/entry/vsyscal= l/vsyscall_64.c index c9103a6fa06e..0b0e0283994f 100644 --- a/arch/x86/entry/vsyscall/vsyscall_64.c +++ b/arch/x86/entry/vsyscall/vsyscall_64.c @@ -124,7 +124,8 @@ bool emulate_vsyscall(unsigned long error_code, if ((error_code & (X86_PF_WRITE | X86_PF_USER)) !=3D X86_PF_USER) return false; =20 - if (!(error_code & X86_PF_INSTR)) { + /* Avoid emulation unless userspace was executing from vsyscall page: */ + if (address !=3D regs->ip) { /* Failed vsyscall read */ if (vsyscall_mode =3D=3D EMULATE) return false; @@ -136,13 +137,16 @@ bool emulate_vsyscall(unsigned long error_code, return false; } =20 + + /* X86_PF_INSTR is only set when NX is supported: */ + if (cpu_feature_enabled(X86_FEATURE_NX)) + WARN_ON_ONCE(!(error_code & X86_PF_INSTR)); + /* * No point in checking CS -- the only way to get here is a user mode * trap to a high address, which means that we're in 64-bit user code. */ =20 - WARN_ON_ONCE(address !=3D regs->ip); - if (vsyscall_mode =3D=3D NONE) { warn_bad_vsyscall(KERN_INFO, regs, "vsyscall attempted with vsyscall=3Dnone"); --=20 2.47.2