From patchwork Mon Mar 11 16:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pasha Tatashin X-Patchwork-Id: 13589086 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 33BE4C5475B for ; Mon, 11 Mar 2024 16:47:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A02AA6B00D6; Mon, 11 Mar 2024 12:46:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 93B176B00D7; Mon, 11 Mar 2024 12:46:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 71BEA6B00D8; Mon, 11 Mar 2024 12:46:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 56B836B00D6 for ; Mon, 11 Mar 2024 12:46:57 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id ED2241A040E for ; Mon, 11 Mar 2024 16:46:56 +0000 (UTC) X-FDA: 81885337632.12.2536EF0 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf10.hostedemail.com (Postfix) with ESMTP id 43BEEC001E for ; Mon, 11 Mar 2024 16:46:55 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=GGQHlpvJ; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf10.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.179 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1710175615; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=NGLgnjdxSReHw9wlD+FW1YibHNtCAjZjXR36RT3BbYQ=; b=k31nVnO0RaE+zhKXzUW//vYxa48YVrxpV6+tIsWIyOzDNvzlUs/CtAzXZ/veCzWgTFMJf5 Mpv93KV6FpIdPbKn0BRyo55aCURD1VoSr+CcbrQ7NXaPFWm4vicczszPF7Wd6Wj38uOnrf mJ7rH5+yuFfcsYnJjzGu/TNiIWU2OE4= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=soleen-com.20230601.gappssmtp.com header.s=20230601 header.b=GGQHlpvJ; dmarc=pass (policy=none) header.from=soleen.com; spf=pass (imf10.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.222.179 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1710175615; a=rsa-sha256; cv=none; b=zSVw4c7zF6tTEA91CL09Tlql48uSwH5lpfPbnx43xj2LK4hXrbi13HIdIaTqCJYaWX11Wb Jhs0NgqDoudB4BurRp/mjzhoffxLORDgi5PgGoC1YzWgIGRLTmpDWy8C7whHkq4UmiRNdI YhfubQhqAJl+qV1enImsVq39ctnguA0= Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-78822e21a9dso149149085a.2 for ; Mon, 11 Mar 2024 09:46:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen-com.20230601.gappssmtp.com; s=20230601; t=1710175614; x=1710780414; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NGLgnjdxSReHw9wlD+FW1YibHNtCAjZjXR36RT3BbYQ=; b=GGQHlpvJYpQMqGQcanF7Pc7eQShivWWX80uuEhmx9x4qmlZ7xslEKjFZRSmBow/o92 ccIPRAIT4/DYmCSCvkHve2XWJj4r+wQLNKJH4uFD8xBL52Pojo7lhWFFBmQQZf/Y5dG0 jPmjMpA9ZiZo7DIn7sJOc0YRsxtcaqRA+/VywY7oYECLm+pUpj6ZdfRHiUxakl/uIvkd o5HmL+lxxMAU3VN7TAAe0vv9J35IhqFwBus4/JAR7SuNNAC4wHk+rKcK1BKNzNXu1g0y 4cHL9ccpHJF3PwNVnRgRF2p1xTPLekMmBQ6oIBB+fqee5hhgJTQDMnbLCuOiySjqivCW 18TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710175614; x=1710780414; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NGLgnjdxSReHw9wlD+FW1YibHNtCAjZjXR36RT3BbYQ=; b=iYOrRkCJp0IIcsYEVpjZLxV7EJYI41bm3QyVlUiBK87DHb+3EHmMTtpjfzsjkGV3Hz 6vqgfdFAb6Kj9FRg8SUtAdIyCFj2191queyuyNF/vphFOZAoBhVm7UQk8GvU30SysdtX u779iCL3BwkG8BvYGBYWZuhJgwtN+cbuPVFEuO6MuctnHaW1sWbTzmnIVNsrbbIXFDA7 i34bOcIcFoo6wZ/U+drpEZAzlyhUr8taeFa4DMtfl0j9RrPrEZWE/FCS6oKkVQs4fRDv oXktIsWbmGSXM0xAyEVMjWV83XOuNYzFXywI3FTcl0Dy5VT4tE17kNlrXJ9f2GAE6hGl 7o0g== X-Forwarded-Encrypted: i=1; AJvYcCUB+ZTHfnXUNImjUbk84qFLvsr07UcF0ZszZyNaff8XUQpjb3T4Z93lRY/JUQg95As6hN4x+AJtvq5gcwlcOi/bYrY= X-Gm-Message-State: AOJu0YxZltOXIet93FgrTd+Yy0XpFkbK/dpALy/2I9R84bgCxIS0WpMq drqwbZERP7gup+T5vODHwhbFFG0bnyknQKlDQUhzDICp71vShl0wiHSEsSN4ei6bqFPOJ0/7yy+ kMSE= X-Google-Smtp-Source: AGHT+IHiFimL/uL6CiZ0/ffUHb5GjnvMvZQk5uciXsXYpJX5LXGSw9tTbmvr67JCBeLYBzWo/uqLsw== X-Received: by 2002:a05:620a:45a1:b0:788:4e44:a9b7 with SMTP id bp33-20020a05620a45a100b007884e44a9b7mr11466669qkb.78.1710175614423; Mon, 11 Mar 2024 09:46:54 -0700 (PDT) Received: from soleen.c.googlers.com.com (150.254.86.34.bc.googleusercontent.com. [34.86.254.150]) by smtp.gmail.com with ESMTPSA id d27-20020a05620a137b00b00788228fbe05sm2851589qkl.17.2024.03.11.09.46.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 09:46:54 -0700 (PDT) From: Pasha Tatashin To: linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, x86@kernel.org, bp@alien8.de, brauner@kernel.org, bristot@redhat.com, bsegall@google.com, dave.hansen@linux.intel.com, dianders@chromium.org, dietmar.eggemann@arm.com, eric.devolder@oracle.com, hca@linux.ibm.com, hch@infradead.org, hpa@zytor.com, jacob.jun.pan@linux.intel.com, jgg@ziepe.ca, jpoimboe@kernel.org, jroedel@suse.de, juri.lelli@redhat.com, kent.overstreet@linux.dev, kinseyho@google.com, kirill.shutemov@linux.intel.com, lstoakes@gmail.com, luto@kernel.org, mgorman@suse.de, mic@digikod.net, michael.christie@oracle.com, mingo@redhat.com, mjguzik@gmail.com, mst@redhat.com, npiggin@gmail.com, peterz@infradead.org, pmladek@suse.com, rick.p.edgecombe@intel.com, rostedt@goodmis.org, surenb@google.com, tglx@linutronix.de, urezki@gmail.com, vincent.guittot@linaro.org, vschneid@redhat.com, pasha.tatashin@soleen.com Subject: [RFC 11/14] x86: add support for Dynamic Kernel Stacks Date: Mon, 11 Mar 2024 16:46:35 +0000 Message-ID: <20240311164638.2015063-12-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.44.0.278.ge034bb2e1d-goog In-Reply-To: <20240311164638.2015063-1-pasha.tatashin@soleen.com> References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: uaj1tfpqudyrtx3r65oeib9eoc45z668 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 43BEEC001E X-HE-Tag: 1710175615-3387 X-HE-Meta: U2FsdGVkX19FonC8Kg7gsMaHylFHQBtda7M2B+WhpKTcd+oTBwbZ0avXMB0Ge9SkG8oxmIc0m6OlJlgv+CIz+4Hm/irCeVX9OwbDR2rYmUeMLBj7UVNUZLLLLhCBIxxqoFdcQMHDvhMAU8rYsSvKMVRRUiCP/rk53yy8T1D9xG0gjZwx9HLiSIh6N93ctGpjd+1Uy5be9ugWEcPtkN9TBDbTKyOY4k0DkXsE+UgcPoWHcpqP/fb3Mo9JZnRJy5C4I+kl6u7Wsg8r9lJJPnBV41pLTdAd7lRkQEyjCoajbhE/dfnp+1lNBuvSdfpnIu3pOrOOJS5PSZX6NJcxQx3oX8SSmt05YjyVyGplnmL8ykz0i3PJhZOx/bKNVs9aPvDwhx+kaijVXYgL2Mj3sJlRF7mlk3+KJx05w2xzBEZJhq42uVkw7CclEjjsLI266715LRRQJFq3i2yOLrQe5ssSSUGw3nlNmT6j37x0grfYsNWR2xP8GvJ+IZtr8sQavj6ZQXv1aCz5cDncYFzG5C9Jvw8SawAxThnop2knWFicHudcLAqmPF53HtTTrBaRHblXw31QnGilBmHfMZT4WUFsByAGjbWARK9hpL+VYzYHm2AOSpcID5QuohIhIyLI192s/DYHfu7dWTyvSfuVK6w0HzaBaTF9QVJaohOOA6iVQNxsVAr+Wp+bpk6Z2D5MvkffPG04dUcTr1Jsp4vt26WLm0E5gu7kznVW3tjTa+kMgWGit/YgeV/aN11AAhe0QQhOWvS1oo1X1vObgIevrnPjwa5uZPaQn9AdOCuyUq7U8F1iR7SsHntkV1/ZUWkdegasCCoEbWtxqc9zugjiPnWnP2ywqMb+sGfY5yZvNMIkCFvFuotAEq4CrzLXoUxqP9DlA8P6Xbk5W1zf2WJoa9xet9YSFTsa56E9gkL7xYOW4u3Nbst3j6PRMlX4T/9Ktp/MWqLf3CqpJw3IodyRtis of/mJn7V shJek3JbLJFoKJYDxE5nrKfI1np4Zxi/fp4zB3atmOt97JPCyKBELdY6BB4uTSirq+OwxdGm6AyBkv+xXW2ljYiJKkacFu0ptGyKoXRLgGg6Zk6pvAEOdlurzX170wu7xI1GnQ/0aL0Nros4AvjEByPoM/TkHpsXMAmNHGHBVsH54Dps= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Add dynamic_stack_fault() calls to the kernel faults, and also declare HAVE_ARCH_DYNAMIC_STACK = y, so that dynamic kernel stacks can be enabled on x86 architecture. Signed-off-by: Pasha Tatashin --- arch/x86/Kconfig | 1 + arch/x86/kernel/traps.c | 3 +++ arch/x86/mm/fault.c | 3 +++ 3 files changed, 7 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 5edec175b9bf..9bb0da3110fa 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -197,6 +197,7 @@ config X86 select HAVE_ARCH_USERFAULTFD_WP if X86_64 && USERFAULTFD select HAVE_ARCH_USERFAULTFD_MINOR if X86_64 && USERFAULTFD select HAVE_ARCH_VMAP_STACK if X86_64 + select HAVE_ARCH_DYNAMIC_STACK if X86_64 select HAVE_ARCH_RANDOMIZE_KSTACK_OFFSET select HAVE_ARCH_WITHIN_STACK_FRAMES select HAVE_ASM_MODVERSIONS diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c index c3b2f863acf0..cc05401e729f 100644 --- a/arch/x86/kernel/traps.c +++ b/arch/x86/kernel/traps.c @@ -413,6 +413,9 @@ DEFINE_IDTENTRY_DF(exc_double_fault) } #endif + if (dynamic_stack_fault(current, address)) + return; + irqentry_nmi_enter(regs); instrumentation_begin(); notify_die(DIE_TRAP, str, regs, error_code, X86_TRAP_DF, SIGSEGV); diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c index d6375b3c633b..651c558b10eb 100644 --- a/arch/x86/mm/fault.c +++ b/arch/x86/mm/fault.c @@ -1198,6 +1198,9 @@ do_kern_addr_fault(struct pt_regs *regs, unsigned long hw_error_code, if (is_f00f_bug(regs, hw_error_code, address)) return; + if (dynamic_stack_fault(current, address)) + return; + /* Was the fault spurious, caused by lazy TLB invalidation? */ if (spurious_kernel_fault(hw_error_code, address)) return;