Received: by 2002:ab2:710b:0:b0:1ef:a325:1205 with SMTP id z11csp796789lql; Mon, 11 Mar 2024 19:22:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXpNEDOU9x8vlAil+5ipNS5YRboagMQjAOCJh0MY8YJsDBbLlwsx5wGpvCkmQQJwNfm6C1CafZ/1fLDGL26MyKJadVkEHUcW9455tydSQ== X-Google-Smtp-Source: AGHT+IEaiVhnlP+DDA5x29FdJL6J3+ryElsRR+N1bfC6ebxm4O5mSR2OmoKnWhwEPWZkekGtvLQz X-Received: by 2002:a05:6358:42a4:b0:17b:eec9:8ee8 with SMTP id s36-20020a05635842a400b0017beec98ee8mr11464636rwc.12.1710210132799; Mon, 11 Mar 2024 19:22:12 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710210132; cv=pass; d=google.com; s=arc-20160816; b=JVJ10zidRLP7QoMNF2BknjGzQPZyE6vBDyCO5E4JA2VY/U5k22xmAe9QanDfK4MBqu n5/QiX+/C1SwnS7KbUfpabqZNFkPpwFEstmk0pHKsGiaohSJZvXCITZi2IH0xbMsGZ0E EAeCzNVVE8lk7mcUZVQCAgmMw4Ryj6u9lgqPCcBn2F0AkDIv/o6Xfyy3vM0QqDZm77mh FAyaViQf8imo2+lsC+k8ZyAFSMYYvFmRWL6wnsa32EyB7IPGJZpxEc2nO+VwqWYH3S9p qm7t2scijzXNdxTInytFbWL1VdsoKumyKwi/oxQLUOCIX2RVC/oEspc0+bNxOiiHrm+9 4oaw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:references:in-reply-to :user-agent:subject:cc:to:from:date:dkim-signature:dkim-filter; bh=25o8RezCz/80azo9KF9KOroEFSSWkg8pHxdIqDA7QWg=; fh=1y0jOX4IHl+vFbBTaDjpJLOx85rzc2rhAQ7KFGB90YE=; b=RVOm0Ngat2txXYAXVqFf/YxQHXCm/ruz/jd0coDRa5NEtWE1PGzDKCZky24h//GVBB I1dFe+y/mPyyfr0D4ua1rzG3suk61BE5S05FoRtF8A5BXu9HSp2WuQ+BBEDsMR0rP7XL SHPhlK6YRdquyCa+yYhgF6UUQmfEGXZRR5sx9z59cOYQIk1cjNle1Qp2Z7Ym+Z+qtCWS tWCfyg4GtRejY/Yz6q8CBswKhsoG1HFVN/gWZgvtgyggBctPHt919LXGJrZQPog/5kWZ cBwtAmMU7SR1e/RGw2HGlNGUfL0W3Yn11311adUv9AlcDuzD86maovQ/zJGCgqOp50T9 hLlQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zytor.com header.s=2024021201 header.b=MjinCQYJ; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-99765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id s17-20020a632c11000000b005dc88260f76si6024205pgs.330.2024.03.11.19.22.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Mar 2024 19:22:12 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-99765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@zytor.com header.s=2024021201 header.b=MjinCQYJ; arc=pass (i=1 spf=pass spfdomain=zytor.com dkim=pass dkdomain=zytor.com dmarc=pass fromdomain=zytor.com); spf=pass (google.com: domain of linux-kernel+bounces-99765-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-99765-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=zytor.com 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 5120CB217E1 for ; Tue, 12 Mar 2024 02:22:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4F02BAD32; Tue, 12 Mar 2024 02:22:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b="MjinCQYJ" Received: from mail.zytor.com (terminus.zytor.com [198.137.202.136]) (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 6281A945A for ; Tue, 12 Mar 2024 02:21:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.136 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710210122; cv=none; b=O6z6YpVaLby9BFLvdxNDzN+DtzTmwKBfCcgh/OgWmhu7iQ9gSSDOQXCqhFaUTYMSYcJ37NpaUxXDkcnfco/dDTksn3OdZBqWUjXDYCg5TwRxAjzNVbSdsQW5P3SeTHNCtv9MF76p8a7wGJ6jYIyR3WgdhkZfVAp+HRVj/58fnsA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710210122; c=relaxed/simple; bh=epRTf1wLs43NkiHRFVg/kOBMSreaIeFhsSZmxUVSZMU=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=RSviRCyQUoZYDczvxDl5MEePofjQFVb6tcFxmrSizv4zAzBf+r8oUthUnANCYki7AqKp/LKl7DQdgbwA9FS9l3QwGf+F8J1DeQZetrR+ZIlEgqpG6xQ5vLRmIibV/MEUijY8hYsm8xJThDQwe8qRDh3r60CtuUMpLObG8MuTeEM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com; spf=pass smtp.mailfrom=zytor.com; dkim=pass (2048-bit key) header.d=zytor.com header.i=@zytor.com header.b=MjinCQYJ; arc=none smtp.client-ip=198.137.202.136 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zytor.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zytor.com Received: from [127.0.0.1] ([76.133.66.138]) (authenticated bits=0) by mail.zytor.com (8.17.2/8.17.1) with ESMTPSA id 42C2KvjU1107798 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Mon, 11 Mar 2024 19:20:58 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 42C2KvjU1107798 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2024021201; t=1710210062; bh=25o8RezCz/80azo9KF9KOroEFSSWkg8pHxdIqDA7QWg=; h=Date:From:To:CC:Subject:In-Reply-To:References:From; b=MjinCQYJOwkr/GeS6myIyc5fiKaO2Jc6L1Aas4l12yyMkbi9pF+p3BmHPieTdqOkZ cGhZ0/0Ct+NBK+Ta954sRgeRzGlC0WPeICXOLDfBHReqMVl357P7jT+TYr+2GH/R1e JPaS5v8Ps3uU8nBBmWFIRiu7qb+1Ylkf2l46STFhRAEZrQ5AWPbrD5dw7d7pvFuoK/ nWbYe1zFwItOZ5VeNTWoyhGMSF7vxUaVH4IsAbcTMVwp+mzVJSDoJTPwkYuveTeQNR +uGe4p9G2m8nf/rVw4evqkBOahg2pka7mZfLvHMYdQcK3d46AP1XjtyttzxZqnxtsg 3s8ZDreVs1uww== Date: Mon, 11 Mar 2024 19:20:54 -0700 From: "H. Peter Anvin" To: Andy Lutomirski , Dave Hansen , Nadav Amit CC: Pasha Tatashin , Linux Kernel Mailing List , linux-mm , 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" , 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 User-Agent: K-9 Mail for Android In-Reply-To: <0645946c-f4f5-43b1-a9a0-03ed139036b3@app.fastmail.com> References: <20240311164638.2015063-1-pasha.tatashin@soleen.com> <20240311164638.2015063-12-pasha.tatashin@soleen.com> <3e180c07-53db-4acb-a75c-1a33447d81af@app.fastmail.com> <08EFDEDB-7BBB-4D9C-B7E5-D7370EC609BE@gmail.com> <0645946c-f4f5-43b1-a9a0-03ed139036b3@app.fastmail.com> Message-ID: <83E86178-FBC7-49C5-B624-8B8106D10CBC@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=utf-8 Content-Transfer-Encoding: quoted-printable On March 11, 2024 7:16:38 PM PDT, Andy Lutomirski wrote= : >On Mon, Mar 11, 2024, at 6:25 PM, H=2E Peter Anvin wrote: >> On March 11, 2024 5:53:33 PM PDT, Dave Hansen wrote: >>>On 3/11/24 16:56, Nadav Amit wrote: >>>> So you can look on the dirty-bit, which is not being set >>>> speculatively and save yourself one problem=2E >>>Define "set speculatively"=2E :) >>> >>>> If software on one logical processor writes to a page while software >>>> on another logical processor concurrently clears the R/W flag in the >>>> paging-structure entry that maps the page, execution on some >>>> processors may result in the entry=E2=80=99s dirty flag being set (du= e to the >>>> write on the first logical processor) and the entry=E2=80=99s R/W fla= g being >>>> clear (due to the update to the entry on the second logical >>>> processor)=2E >>> >>>In other words, you'll see both a fault *AND* the dirty bit=2E The wri= te >>>never retired and the dirty bit is set=2E >>> >>>Does that count as being set speculatively? >>> >>>That's just the behavior that the SDM explicitly admits to=2E >> >> Indeed; both the A and D bits are by design permissive; that is, the=20 >> hardware can set them at any time=2E >> >> The only guarantees are: >> >> 1=2E The hardware will not set the A bit on a not present late, nor the= D=20 >> bit on a read only page=2E > >Wait a sec=2E What about setting the D bit on a not-present page? > >I always assumed that the actual intended purpose of the D bit was for th= ings like file mapping=2E Imagine an alternate universe in which Linux use= d hardware dirty tracking instead of relying on do_wp_page, etc=2E > >mmap(=2E=2E=2E, MAP_SHARED): PTE is created, read-write, clean > >user program may or may not write to the page=2E > >Now either munmap is called or the kernel needs to reclaim memory=2E So = the kernel checks if the page is dirty and, if so, writes it back, and then= unmaps it=2E > >Now some silly people invented SMP, so this needs an atomic operation: x= chg the PTE to all-zeros, see if the dirty bit is set, and, if itt's set, w= rite back the page=2E Otherwise discard it=2E > >Does this really not work on Intel CPU? > Sorry, I should have been more clear=2E Hardware will not set a bit that would correspond to a prohibited access= =2E