Received: by 2002:ab2:6486:0:b0:1ef:eae8:a797 with SMTP id de6csp567391lqb; Sat, 16 Mar 2024 17:41:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCU2v91vNbjZOOZvCJeUeJnQhLm7p94mE4H03t/Q6WdLvq4+hAs+OXrOU8WCOD8FNpGwlcJLdHDsLpHjOZ+3JF+G+V1dHQeOGj0YJC/6eg== X-Google-Smtp-Source: AGHT+IGIPXMG+HzeEgnjHoIDlKDnu59NyxdZwdTZniddYwq+1POnrTyUhSRv+3KBBGuW4ykpW1rF X-Received: by 2002:a92:60e:0:b0:365:b00e:c3ba with SMTP id x14-20020a92060e000000b00365b00ec3bamr8232630ilg.9.1710636118159; Sat, 16 Mar 2024 17:41:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710636118; cv=pass; d=google.com; s=arc-20160816; b=a0lI3ytG0/e+xZS1bSUAGAN6NfLFYLm0Di+vs6zWROb7JbwCJr6Av8NZCGbPlga3F8 jP5/IGsnwx01SIfmybdw+K2bN80fD3jNDAXfyCQiJzMjABJmQyB7HbiFW4khZylbUf7f zpuvHN2xUvgBHS58upOt/mUF5EFXjlz1JoRzsYL6vJkIWPoA9J7hj69V4NQEEhiGBaph 8IILIL8gj7LjKInrSLNblgOmhXe/IUuAyu9hrpQ+nr6OCR1jFk9PVkvbZJhHM5kbLpfD lnis5MlmKET6/D4oXcME88hxEOSwSg1lNuPclCpdUmP3J/tMUInF7C7o6IirOwXxM2gW PqiA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=861eAApZXU3vRWwZN8NtN/fYtVMSBl0R3WWZ/C06Z0Q=; fh=kh5GWyy1cmeJPZt5U32t+PHDKX4jxEUBcSwQemZ1QFk=; b=U1HfzK2pBIZtLhi4slAmbHC9gQaIYIdLgz66JHaZA2RRRavO3NlCqIU7Swx12D8W9X BJn3xNoX0OBjSp/9B2RsG17LbdeZuqy6LNMOscAbnINGzQvmJbdZhtD9u66UnA+s1kwP 5vOErTMvETLxmYqW1O9G8rwmgOB5pj7bF5L/LIEwYwSa9FKYKTSPIEuDeiyOWyQPBDgR aHMnfoVECqL5GJ43HHGnRVFqGil/uxGQz2qiUHnl1i1rXqr0fkA6cx/q6cZk5wz3mBjv OyAiB839pCr5SuhPEEBQanGC8x4cv1tfkf0V7AHxVHzI25mYDPt7ispeC/5S6uS3oK+K JLYA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=r9SxkOpx; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-105312-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105312-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 13-20020a63154d000000b005cdfc01b502si5308537pgv.337.2024.03.16.17.41.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Mar 2024 17:41:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-105312-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=r9SxkOpx; arc=pass (i=1 dkim=pass dkdomain=infradead.org); spf=pass (google.com: domain of linux-kernel+bounces-105312-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-105312-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id BF1E6282198 for ; Sun, 17 Mar 2024 00:41:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1B27A1FBB; Sun, 17 Mar 2024 00:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="r9SxkOpx" Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 9AE64173 for ; Sun, 17 Mar 2024 00:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710636109; cv=none; b=X2bkLiHe48hOhjzcpXMoXbjJeSFzjHTmvLLhk9TnTUggcYed3emn5MkU9kYvdIyBkMi22kf8LT7+h19LwnFaYV1Tg40S0eKNevGUtNtBiU1h3wB7/j8j1I9z9CbCXLd6tThJaCHmHAAH4iY+gTcoQwXnQFZ4QyBb4y9tfoj6mq0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710636109; c=relaxed/simple; bh=swL5pSZGofZVCvafPRaSq1d18g1PPcmvWeKOt9Qqmts=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=fdJrhFp3MgPL7vs3owB2mCOLXd2VVWHPYWbi7CKfTnSB5uHSQVP0SHD5DKfrl8bwP9NASXfFdg/aKpgLE0S8eWlh631bcd5DLfLKK7qqePLSehWRKc7Hb9z3RUy0kPLP7AXk5jwZescywfzMm9H8F3XrC5zkFVmKlSHOcXt7nBg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=r9SxkOpx; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=861eAApZXU3vRWwZN8NtN/fYtVMSBl0R3WWZ/C06Z0Q=; b=r9SxkOpx8uSxPEXiP+T4k4YbNJ S3eEb2b5Vpi8f6A8oMByvAXoYB3SXV6n+MW35TNtZ7/qEhUzgzNoSUcmcbWPLYOFco0/m3wpt0CQj iCFUMsRj8nv73rZCeRdj72QGjSpko+mUlLVALjH7fNEoDhCu9RvOf6LarDDMbRN9vigskiOWlsC5j ebFn0EAeFzGeOflSwEf+ArT0jpvN76o2U8aCtX1/usKVBkF1kjzsQMrHT37Nc1Oo3JYnbL8Np5Pfu MEeOQbTPrhoWVACzqbRyPrXaJxxaWBzc/xBakX1Xk5LKF2GA9+wYvYv7Y3Ou/I4gnkz+WK8Rv6wwK ZsMXA7XA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1rleaj-0000000Dbuk-2kaT; Sun, 17 Mar 2024 00:41:33 +0000 Date: Sun, 17 Mar 2024 00:41:33 +0000 From: Matthew Wilcox To: Pasha Tatashin Cc: "H. Peter Anvin" , Kent Overstreet , 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, jacob.jun.pan@linux.intel.com, jgg@ziepe.ca, jpoimboe@kernel.org, jroedel@suse.de, juri.lelli@redhat.com, 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 Subject: Re: [RFC 00/14] Dynamic Kernel Stacks Message-ID: References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> <2cb8f02d-f21e-45d2-afe2-d1c6225240f3@zytor.com> <2qp4uegb4kqkryihqyo6v3fzoc2nysuhltc535kxnh6ozpo5ni@isilzw7nth42> <39F17EC4-7844-4111-BF7D-FFC97B05D9FA@zytor.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Sat, Mar 16, 2024 at 03:17:57PM -0400, Pasha Tatashin wrote: > Expanding on Mathew's idea of an interface for dynamic kernel stack > sizes, here's what I'm thinking: > > - Kernel Threads: Create all kernel threads with a fully populated > THREAD_SIZE stack. (i.e. 16K) > - User Threads: Create all user threads with THREAD_SIZE kernel stack > but only the top page mapped. (i.e. 4K) > - In enter_from_user_mode(): Expand the thread stack to 16K by mapping > three additional pages from the per-CPU stack cache. This function is > called early in kernel entry points. > - exit_to_user_mode(): Unmap the extra three pages and return them to > the per-CPU cache. This function is called late in the kernel exit > path. > > Both of the above hooks are called with IRQ disabled on all kernel > entries whether through interrupts and syscalls, and they are called > early/late enough that 4K is enough to handle the rest of entry/exit. At what point do we replenish the per-CPU stash of pages? If we're 12kB deep in the stack and call mutex_lock(), we can be scheduled out, and then the new thread can make a syscall. Do we just assume that get_free_page() can sleep at kernel entry (seems reasonable)? I don't think this is an infeasible problem, I'd just like it to be described.