Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp741630lql; Mon, 11 Mar 2024 16:42:03 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3cUs0AGOo5JnALuFgMmxRQcKN64CFEomrxMF0K1BS/aeU8EPaedcgEPijonxE224+hr1xCPhK9HZlzuQRnAzKbk0ZB7WzRufeGixc1w== X-Google-Smtp-Source: AGHT+IHAUtv0WkIg/tNrfCOYzdB+DypSR7HLw2iKT55PKJlk/cexeUDq1UHkEj6+RUeHJipknGBK X-Received: by 2002:a0c:e78f:0:b0:690:de5f:2127 with SMTP id x15-20020a0ce78f000000b00690de5f2127mr2068830qvn.36.1710200523063; Mon, 11 Mar 2024 16:42:03 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710200523; cv=pass; d=google.com; s=arc-20160816; b=HXmWAMaoMG4J3whDnbG0fJ8VbFUe2SnWAN050pX0xPUW7P7wwCTJNRdpunuR1NJBKO B3KEzSxdVSiTBISUP/D03kFB5ZKYg4//exZbJ5QObO/bqDZKhGce+l2YpDr514Txr8Zs up/WjCKSlDAOXtJCs6kVXn+gzrrZsUdwsvJzGPU/H6yHKFKTvTJJ/iaKBgaiqcHH5msB lnzBhi/pf/DAmyJlKDisKTmWv7gCYOg93052+GAGlNl6h+001/WrvZVX0Kd5mbn37lCv 2ZZ5E8ihEc8dI7f+1pAQmq0Ltk1vIJx3B6x7AhVdzYU7H5KPrWcqxq8M5PxVZw0conOt q4uQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=subject:to:from:date:references:in-reply-to:message-id:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:user-agent :feedback-id:dkim-signature; bh=TXUC7EBSF7yZADz35qLKuiZ6DysFeoumL5EnOhDC4Mw=; fh=sEET2dSEv6/QNJ3BEhRnHXzfn86A2mazBqRi2g2klzk=; b=FwkaZRTdMeo3qTw7CPRMcgZQ7YlkSnGgfDSvFOEK6h64cJUPEdqd/j5i3YBQQuhgav ngz3Zah0qQCtHy8Gz1raF/mxi0yLH1gO/vbhdYSke8yqNQnKVqGIOl1hJzs4+AYj5AwN ZDQkUmLuP98pwHAzommCM+68zIp2vv9vyiIuHxxpvt9dL0FK6cHS+iEDjMxz3QpGy1Q8 oXut2Gq0vSP5uG0Dc8dGgdHvZa0j9gSPQA3Jmi/Xctrj6zuY8YFqNB8LF8RY7LqfMXtN ZHDrW8bhzGLvRlFgmBwhlYlwgtzDQTAiey5uigCz3KZOPrxpfRVZBfyOsaSpUuGv1C8A cT1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L5ceodxM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99670-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99670-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id jl11-20020ad45e8b000000b00690be08e004si6695729qvb.45.2024.03.11.16.42.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 16:42:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99670-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=@kernel.org header.s=k20201202 header.b=L5ceodxM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-99670-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99670-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 8703A1C21162 for ; Mon, 11 Mar 2024 23:42:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A3DEA5A4EF; Mon, 11 Mar 2024 23:41:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="L5ceodxM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 B856C5A4C6 for ; Mon, 11 Mar 2024 23:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710200512; cv=none; b=nAhl0XQVsGbLE+B5k3n/Wb4QSpAvNEYIs5jh69T/5Ab9yH7DxyhRSERmMF+sJYPdDKGLPShTxY75boxFf1cp35KX5bDVRVkpCimGcUOmpsHZlfh7IX4dTt9KPGJLkHd1UDk28kfFCn9WPS4rcWzbdNi9Hd1xtgE1bhn8sVICatU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710200512; c=relaxed/simple; bh=jjeKu/Fq+iDGPMTBTzqSsDgUhOYnfDFIBWLtDwFFWVc=; h=MIME-Version:Message-Id:In-Reply-To:References:Date:From:To: Subject:Content-Type; b=oFrRdabZ1Kpx+EBw7RGh0Bi/lLsZe0yM3VM+w0MTt4ZtEwh83JUwjUktkz+JCBr/m+1lLBrlpzOOxUfr78IlZvpRkvsS1i0mpZ6H5QkIN87TYIaiJG+1U24Qsffw3MROaaxzRw3kfs6ikZD2pf2eXIOboMgK96a5tfz3YEB6Qwg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=L5ceodxM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8747C43390; Mon, 11 Mar 2024 23:41:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710200512; bh=jjeKu/Fq+iDGPMTBTzqSsDgUhOYnfDFIBWLtDwFFWVc=; h=In-Reply-To:References:Date:From:To:Subject:From; b=L5ceodxMdFbJFXBShdbQkvUMn/xDml0vkeA8PIYiut/kgG5lKmnFORrqExlCq3iLX e0SnljJlSCIWfoRxLawkKz3zlKR1lcXGKkC43pSlHZ/b9QU/lgc+RkWp3gX3CK/Tth MEpV00gjknFVBvdvQ+0w35rpnuc42fDJnkGzeNxP8GZB5+H2yEcAKLOUHQ8yht9yX4 1I0LsY+CtASv7tn89qY7eof5Se28JWHBAEPVPSIXxWQUlo2E8gGugH/XLeLsgh7ZJL /FSK8ihDRPFUHDNhRfJlYHU4SQbnAoPAtbv6ZF7aO6vw9sjtsL9z0okrLjiNdTeuJg uRb49A1mkt0+Q== Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailfauth.nyi.internal (Postfix) with ESMTP id D51E31200068; Mon, 11 Mar 2024 19:41:49 -0400 (EDT) Received: from imap48 ([10.202.2.98]) by compute3.internal (MEProxy); Mon, 11 Mar 2024 19:41:49 -0400 X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrjedvgddugecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsehttdertderredtnecuhfhrohhmpedftehnugih ucfnuhhtohhmihhrshhkihdfuceolhhuthhosehkvghrnhgvlhdrohhrgheqnecuggftrf grthhtvghrnheptdfhheettddvtedvtedugfeuuefhtddugedvleevleefvdetleffgfef vdekgeefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomh eprghnugihodhmvghsmhhtphgruhhthhhpvghrshhonhgrlhhithihqdduudeiudekheei fedvqddvieefudeiiedtkedqlhhuthhopeepkhgvrhhnvghlrdhorhhgsehlihhnuhigrd hluhhtohdruhhs X-ME-Proxy: Feedback-ID: ieff94742:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id 35B0031A0065; Mon, 11 Mar 2024 19:41:49 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.11.0-alpha0-251-g8332da0bf6-fm-20240305.001-g8332da0b Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: In-Reply-To: References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> <20240311164638.2015063-12-pasha.tatashin@soleen.com> <3e180c07-53db-4acb-a75c-1a33447d81af@app.fastmail.com> Date: Mon, 11 Mar 2024 16:41:28 -0700 From: "Andy Lutomirski" To: "Dave Hansen" , "Pasha Tatashin" , "Linux Kernel Mailing List" , linux-mm@kvack.org, "Andrew Morton" , "the arch/x86 maintainers" , "Borislav Petkov" , "Christian Brauner" , bristot@redhat.com, "Ben Segall" , "Dave Hansen" , dianders@chromium.org, dietmar.eggemann@arm.com, eric.devolder@oracle.com, hca@linux.ibm.com, "hch@infradead.org" , "H. Peter Anvin" , "Jacob Pan" , "Jason Gunthorpe" , jpoimboe@kernel.org, "Joerg Roedel" , juri.lelli@redhat.com, "Kent Overstreet" , kinseyho@google.com, "Kirill A. Shutemov" , lstoakes@gmail.com, mgorman@suse.de, mic@digikod.net, michael.christie@oracle.com, "Ingo Molnar" , mjguzik@gmail.com, "Michael S. Tsirkin" , "Nicholas Piggin" , "Peter Zijlstra (Intel)" , "Petr Mladek" , "Rick P Edgecombe" , "Steven Rostedt" , "Suren Baghdasaryan" , "Thomas Gleixner" , "Uladzislau Rezki" , vincent.guittot@linaro.org, vschneid@redhat.com Subject: Re: [RFC 11/14] x86: add support for Dynamic Kernel Stacks Content-Type: text/plain On Mon, Mar 11, 2024, at 4:34 PM, Dave Hansen wrote: > On 3/11/24 15:17, Andy Lutomirski wrote: >> I *think* that all x86 implementations won't fill the TLB for a >> non-accessed page without also setting the accessed bit, > > That's my understanding as well. The SDM is a little more obtuse about it: > >> Whenever the processor uses a paging-structure entry as part of >> linear-address translation, it sets the accessed flag in that entry >> (if it is not already set). > > but it's there. > > But if we start needing Accessed=1 to be accurate, clearing those PTEs > gets more expensive because it needs to be atomic to lock out the page > walker. It basically needs to start getting treated similarly to what > is done for Dirty=1 on userspace PTEs. Not the end of the world, of > course, but one more source of overhead. In my fantasy land where I understand the x86 paging machinery, suppose we're in finish_task_switch(), and suppose prev is Not Horribly Buggy (TM). In particular, suppose that no other CPU is concurrently (non-speculatively!) accessing prev's stack. Prev can't be running, because whatever magic lock prevents it from being migrated hasn't been released yet. (I have no idea what lock this is, but it had darned well better exist so prev isn't migrated before switch_to() even returns.) So the current CPU is not accessing the memory, and no other CPU is accessing the memory, and BPF doesn't exist, so no one is being utterly daft and a kernel read probe, and perf isn't up to any funny business, etc. And a CPU will never *speculatively* set the accessed bit (I told you it's fantasy land), so we just do it unlocked: if (!pte->accessed) { *pte = 0; reuse the memory; } What could possibly go wrong? I admit this is not the best idea I've ever had, and I will not waste anyone's time by trying very hard to defend it :)