Received: by 2002:a05:6500:1b45:b0:1f5:f2ab:c469 with SMTP id cz5csp1166623lqb; Thu, 18 Apr 2024 01:59:55 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW918pgNXNIV4G+BvSw1tMluFGak18I0Oq/J9c/O3rq0lMf3q+m6xF4MAzYsT2ee2ApGpSKnZOyPlfXQRKQVuEJy6eD30Vi5Ma+XQ6Lww== X-Google-Smtp-Source: AGHT+IHYWPeP6nQFaRXc1/8cucVd1hpTuhArQ6LVJDmODbgbRe478GCPBYM2CktQ6NhAfJ1X2SB9 X-Received: by 2002:a05:620a:478e:b0:78e:a0f0:a372 with SMTP id dt14-20020a05620a478e00b0078ea0f0a372mr2054172qkb.35.1713430795148; Thu, 18 Apr 2024 01:59:55 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713430795; cv=pass; d=google.com; s=arc-20160816; b=u0Hfq58X011XsSnYchzhrv3E32auDtIvVJrDWgN2tPa8P7hUJoFA8aI8e2CMDw5vjS 1Vqp2RQELKZWsy9cfCmPpdLJrh3bxQ/gBFvB56PLOvYwLL7YCSU1nqFf+6HnxxRlNo1U VEY8UQHmF3yqtnnDlrgEzuxEuA8wOFNS7nhhGVuZmFAhLjODhZV10FOmy3t2QGGe3/5W rfcw4RgiUDHRkz0e6SPA2vgDy1jWlsUUGRAyprqAXd8b67YT3knY3FS8+VN1C3d64uRg e6ByoWUU26zayXcexVY/wQaQ8xDtA5adlY2KsSa9ki5u3lgdcKrxYgmiJ94c7B/++6hp UaOg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=3DzCTW/rvviKfEef1seIKYEq7DyCVwKK623GNOwOcOY=; fh=0LtN/7Wqv4TiuiZ2vHbG92XLjRfD4OWg3yabBFAKqU4=; b=qi09vaqQOc3+8Kjhh+cM1nuL1IxlJSZ/Qn2EBA6fpMB5WxXhGJShpWJz4NZjtEbWJP vpH4NcpJEjh7j6gg7x9bKdBl3p1v+3lDkgEGvse8rzekHfx9ZyZHzSDA5ZNQwoTehco7 ug0o9iHH4hy3ThJIPYvaeq+Wa7oSN7KbVZ6hyVHxGq6Pn+amQMV9mFYv067FnP2exgzh 7Qz5ecOWglhL8irs2MqnAUgfeJEBGfvzSQJWtNfoUE852aSSRBvznKehAOO/I4XtATsu T1iJ+J2tWv5JYDu9Gv62qYXsnxpDdv2ZYmxuQHNUN0raW5z4luoAvZ1F8/7HelK3ygd7 sZUw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tJwwBFsN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-149760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o21-20020ac87c55000000b0043447a995b1si971083qtv.336.2024.04.18.01.59.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Apr 2024 01:59:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-149760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=tJwwBFsN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-149760-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-149760-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id AE22D1C20E3B for ; Thu, 18 Apr 2024 08:59:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DA04D15A4BD; Thu, 18 Apr 2024 08:59:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="tJwwBFsN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="9qCIBcLw" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 2FF2615AAA8; Thu, 18 Apr 2024 08:59:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713430751; cv=none; b=boAxutmh2R+CYuOfPkiNVxWBlEBm0W56mpUcuYRVfqfw6nCPhbxvIXrJ0piZjRosDH986idKjl0U0x3Q69zFr50NP7cD/tq5zloAoKamaGdb7iMJgQm5GRKmezl4XpnzVWA2G46kg/KetLWq18AQVsdqflVjV+JLZLKVlg5Zy3k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713430751; c=relaxed/simple; bh=ZEsPCpG7/bePMkAti19PTun4xE4R1F48IXuZVXgQlZU=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=Oqc6zWrJALiFS9lpmOVOL+YX5ZJX/jG5fHn7Yi8Cu2ZzFmSyl8zltbetNWKXZU/1VOD3UOiBeQ4HjktH8E5cgjE+fpGCo05UhUqVGfsKAbB8KFimaP4bANtVpKeh6L+NveuH40/YC5bLc8UlApTK2whtVG1QUQzsLV42xdLiw2U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=tJwwBFsN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=9qCIBcLw; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Thu, 18 Apr 2024 08:59:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1713430747; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3DzCTW/rvviKfEef1seIKYEq7DyCVwKK623GNOwOcOY=; b=tJwwBFsNXoRUv4mP1ju3vaeExsLeiwwuW6uNnk3N6uxyI+YBMD7EAHxljQSt6O25RmnP3i Bg/dDe6M2OVHxC9PwiXD5xXZsZFOhxJgbli56mYa0J6S+CA1o3jJtSEud8IvzMd6Vw8783 80JuzTQN9tvOmXdprca6vfLrnOn+swHPYEDZOqNZoFTpoHAn76wg5+qwcKrmUf8PQ0jHik FJXHKy7PhzBwb0IsVil5d2TCT15Ov36hawmw3lhAaPgT9FfMHflFtwdAhbZfpMKle8Yg4G w2Uph8yWsg+qfo+IQ9CGNnDyMhpAK+IGrxnR7aRzjlBEZIAt6oaovmr983V1AQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1713430747; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3DzCTW/rvviKfEef1seIKYEq7DyCVwKK623GNOwOcOY=; b=9qCIBcLwAwTdk3oRYLAg7LuXTbthwCq77C5td+QR16SKVW6n/7jc8w5UqD7+gW+hSQCog5 QTyGm6MKbo4bxkCA== From: "tip-bot2 for Xin Li (Intel)" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/urgent] x86/fred: Fix INT80 emulation for FRED Cc: "H. Peter Anvin (Intel)" , "Xin Li (Intel)" , "Borislav Petkov (AMD)" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240417174731.4189592-1-xin@zytor.com> References: <20240417174731.4189592-1-xin@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <171343074673.10875.6611903314262261610.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the x86/urgent branch of tip: Commit-ID: 32f5f73b79ffdef215e2e1bcb6ad74387c0f925c Gitweb: https://git.kernel.org/tip/32f5f73b79ffdef215e2e1bcb6ad74387c0f925c Author: Xin Li (Intel) AuthorDate: Wed, 17 Apr 2024 10:47:31 -07:00 Committer: Borislav Petkov (AMD) CommitterDate: Thu, 18 Apr 2024 10:37:11 +02:00 x86/fred: Fix INT80 emulation for FRED Add a FRED-specific INT80 handler and document why it differs from the current one. Eventually, the common bits will be unified once FRED hw is available and it turns out that no further changes are needed but for now, keep the handlers separate for everyone's sanity's sake. [ bp: Zap duplicated commit message, massage. ] Fixes: 55617fb991df ("x86/entry: Do not allow external 0x80 interrupts") Suggested-by: H. Peter Anvin (Intel) Signed-off-by: Xin Li (Intel) Signed-off-by: Borislav Petkov (AMD) Link: https://lore.kernel.org/r/20240417174731.4189592-1-xin@zytor.com --- arch/x86/entry/common.c | 65 ++++++++++++++++++++++++++++++++++++- arch/x86/entry/entry_fred.c | 2 +- 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c index 6de50b8..51cc9c7 100644 --- a/arch/x86/entry/common.c +++ b/arch/x86/entry/common.c @@ -255,6 +255,71 @@ __visible noinstr void do_int80_emulation(struct pt_regs *regs) instrumentation_end(); syscall_exit_to_user_mode(regs); } + +#ifdef CONFIG_X86_FRED +/* + * A FRED-specific INT80 handler is warranted for the follwing reasons: + * + * 1) As INT instructions and hardware interrupts are separate event + * types, FRED does not preclude the use of vector 0x80 for external + * interrupts. As a result, the FRED setup code does not reserve + * vector 0x80 and calling int80_is_external() is not merely + * suboptimal but actively incorrect: it could cause a system call + * to be incorrectly ignored. + * + * 2) It is called only for handling vector 0x80 of event type + * EVENT_TYPE_SWINT and will never be called to handle any external + * interrupt (event type EVENT_TYPE_EXTINT). + * + * 3) FRED has separate entry flows depending on if the event came from + * user space or kernel space, and because the kernel does not use + * INT insns, the FRED kernel entry handler fred_entry_from_kernel() + * falls through to fred_bad_type() if the event type is + * EVENT_TYPE_SWINT, i.e., INT insns. So if the kernel is handling + * an INT insn, it can only be from a user level. + * + * 4) int80_emulation() does a CLEAR_BRANCH_HISTORY. While FRED will + * likely take a different approach if it is ever needed: it + * probably belongs in either fred_intx()/ fred_other() or + * asm_fred_entrypoint_user(), depending on if this ought to be done + * for all entries from userspace or only system + * calls. + * + * 5) INT $0x80 is the fast path for 32-bit system calls under FRED. + */ +DEFINE_FREDENTRY_RAW(int80_emulation) +{ + int nr; + + enter_from_user_mode(regs); + + instrumentation_begin(); + add_random_kstack_offset(); + + /* + * FRED pushed 0 into regs::orig_ax and regs::ax contains the + * syscall number. + * + * User tracing code (ptrace or signal handlers) might assume + * that the regs::orig_ax contains a 32-bit number on invoking + * a 32-bit syscall. + * + * Establish the syscall convention by saving the 32bit truncated + * syscall number in regs::orig_ax and by invalidating regs::ax. + */ + regs->orig_ax = regs->ax & GENMASK(31, 0); + regs->ax = -ENOSYS; + + nr = syscall_32_enter(regs); + + local_irq_enable(); + nr = syscall_enter_from_user_mode_work(regs, nr); + do_syscall_32_irqs_on(regs, nr); + + instrumentation_end(); + syscall_exit_to_user_mode(regs); +} +#endif #else /* CONFIG_IA32_EMULATION */ /* Handles int $0x80 on a 32bit kernel */ diff --git a/arch/x86/entry/entry_fred.c b/arch/x86/entry/entry_fred.c index ac120cb..9fa18b8 100644 --- a/arch/x86/entry/entry_fred.c +++ b/arch/x86/entry/entry_fred.c @@ -66,7 +66,7 @@ static noinstr void fred_intx(struct pt_regs *regs) /* INT80 */ case IA32_SYSCALL_VECTOR: if (ia32_enabled()) - return int80_emulation(regs); + return fred_int80_emulation(regs); fallthrough; #endif