From mboxrd@z Thu Jan 1 00:00:00 1970 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 DD30AC636CC for ; Tue, 31 Jan 2023 08:46:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71E396B008C; Tue, 31 Jan 2023 03:46:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6CEC16B0093; Tue, 31 Jan 2023 03:46:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 522266B0095; Tue, 31 Jan 2023 03:46:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 433B96B008C for ; Tue, 31 Jan 2023 03:46:37 -0500 (EST) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 104C3160A7D for ; Tue, 31 Jan 2023 08:46:37 +0000 (UTC) X-FDA: 80414463234.02.A9A7E9F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf18.hostedemail.com (Postfix) with ESMTP id C2B561C001A for ; Tue, 31 Jan 2023 08:46:34 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zb0txdNm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675154794; h=from:from:sender: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:dkim-signature; bh=RT0be17qJU4YrT6BGLBw4plPJpfNOohspNBXSp02x6k=; b=ohhgZNDZzZg2bUo69hj50Uq+sDOKc6CmG4Fl2pLND6cEYZ3IYbBhEkuzj7I1wkgjqDXwhc 7XJS5h20DkHVi6Ojcu6vqLQd3AJqaQKg41CARXrUmCD9ltXjg7n5qtDnYZ+zbnvc5CpOR/ 4iA9as9sremr8rPXLcfLIskohVtVpf8= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Zb0txdNm; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf18.hostedemail.com: domain of david@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675154794; a=rsa-sha256; cv=none; b=CAK+MqH/ueyDJwpT76NSOD1eqNAFCeY5dCniLCWxrTL6JXA2Oqp7RdEz1qStlZkGXTfmNU xqUw3cAzDRPSLHqc13vIXPyKqKWCZFVzl2WBRgzWwCOoBLocBvjEXyP0TDr4kK6lccmnDr xwaI/vMBKX8Qc7m5JptF47JDuVH5mUg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675154794; h=from:from: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=RT0be17qJU4YrT6BGLBw4plPJpfNOohspNBXSp02x6k=; b=Zb0txdNmkI6msqnIx8u2aYCjm6uPrPp3ULYqd5d8xkpUFdqB1odtxJEmAb27yr1pD7vOti ktF7k0FvtynPcvc55NSB80I/a01/25cuJ0IHTEWnt7Sd4MtZJU1Rrb+lDia1EI9M4bZJeE Ev6h6gNHhYkGiC38Wm37xAZCLU+VJW4= Received: from mail-wr1-f69.google.com (mail-wr1-f69.google.com [209.85.221.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-645-fE4sDaGpPn2bFnjUJuExAg-1; Tue, 31 Jan 2023 03:46:31 -0500 X-MC-Unique: fE4sDaGpPn2bFnjUJuExAg-1 Received: by mail-wr1-f69.google.com with SMTP id l8-20020adfc788000000b002bdfe72089cso2335080wrg.21 for ; Tue, 31 Jan 2023 00:46:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RT0be17qJU4YrT6BGLBw4plPJpfNOohspNBXSp02x6k=; b=4Ry/bcy1S6xXuUyxTYnhS6E+fHr1Vmm2Gx+eCLlARMWARhQGMlT89GZohsGihYFrN+ UmWTboRr3dtFAboXQN7ZncoQmq2R74zw6dFjQDVkzT3bncAYIOalAoqUhibsHONXbT13 Rvj1winkYfLHXlssv/DFQQBGq67mH/ZfmjmU2p6N1pFXUZxV2kcGd+lDDxzZi/wXg/FX A0GQ4NEhpOT8ZtmYo7qCEnY0xtL//9mqe2r0x7CSU9mn0Pi/zh59FDIKvay+w8ng8jfl zsOLrKoarMofZvbyAhdeceLCoeIcoLulFdAnsQJmUPcmilWqJ9nYiNP98mI2P1ksZAV9 kc/Q== X-Gm-Message-State: AO0yUKW0YNhA17dhnhQabyLItKNNtduTbk2Am9zxhGFNqXpoeyvTCZfE ELar6waLu6DyaBlyZDCp5KXFsO8X9LaTyzK8kOUPPt5q3FQKaWSHpfGc6PUn1kXxvk013yAJvLx kSHALdvQV7Xw= X-Received: by 2002:a05:600c:350a:b0:3dd:1c45:a36d with SMTP id h10-20020a05600c350a00b003dd1c45a36dmr2228088wmq.27.1675154790689; Tue, 31 Jan 2023 00:46:30 -0800 (PST) X-Google-Smtp-Source: AK7set8QpCOBeSom0P3EMkkVT3iDxdmU57NVBunEGbit/G8Vzfu/HJ8buwXfm2TF7WWfzUVYQ1crOw== X-Received: by 2002:a05:600c:350a:b0:3dd:1c45:a36d with SMTP id h10-20020a05600c350a00b003dd1c45a36dmr2228038wmq.27.1675154790214; Tue, 31 Jan 2023 00:46:30 -0800 (PST) Received: from ?IPV6:2003:d8:2f0a:ca00:f74f:2017:1617:3ec3? (p200300d82f0aca00f74f201716173ec3.dip0.t-ipconnect.de. [2003:d8:2f0a:ca00:f74f:2017:1617:3ec3]) by smtp.gmail.com with ESMTPSA id o16-20020a05600c379000b003dc49e0132asm9751166wmr.1.2023.01.31.00.46.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 31 Jan 2023 00:46:29 -0800 (PST) Message-ID: <0e29a2d0-08d8-bcd6-ff26-4bea0e4037b0@redhat.com> Date: Tue, 31 Jan 2023 09:46:27 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Subject: Re: [PATCH v5 18/39] mm: Handle faultless write upgrades for shstk To: "Edgecombe, Rick P" , "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "peterz@infradead.org" , "rdunlap@infradead.org" , "keescook@chromium.org" , "Eranian, Stephane" , "kirill.shutemov@linux.intel.com" , "dave.hansen@linux.intel.com" , "linux-mm@kvack.org" , "fweimer@redhat.com" , "nadav.amit@gmail.com" , "jannh@google.com" , "dethoma@microsoft.com" , "kcc@google.com" , "linux-arch@vger.kernel.org" , "pavel@ucw.cz" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "akpm@linux-foundation.org" , "Lutomirski, Andy" , "bp@alien8.de" , "jamorris@linux.microsoft.com" , "tglx@linutronix.de" , "Schimpe, Christina" , "mike.kravetz@oracle.com" , "arnd@arndb.de" , "Yang, Weijiang" , "x86@kernel.org" , "andrew.cooper3@citrix.com" , "john.allen@amd.com" , "linux-doc@vger.kernel.org" , "rppt@kernel.org" , "mingo@redhat.com" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" Cc: "Yu, Yu-cheng" References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-19-rick.p.edgecombe@intel.com> <7f63d13d-7940-afb6-8b25-26fdf3804e00@redhat.com> <50cf64932507ba60639eca28692e7df285bcc0a7.camel@intel.com> <1327c608-1473-af4f-d962-c24f04f3952c@redhat.com> <8c3820ae1448de4baffe7c476b4b5d9ba0a309ff.camel@intel.com> <4d224020-f26f-60a4-c7ab-721a024c7a6d@redhat.com> <899d8f3baaf45b896cf335dec2143cd0969a2d8a.camel@intel.com> <27b141c06c37da78afca7214ec7efeaf730162d9.camel@intel.com> <6a38779c1539c2bcfeb6bc8251ed04aa9b06802e.camel@intel.com> From: David Hildenbrand Organization: Red Hat In-Reply-To: <6a38779c1539c2bcfeb6bc8251ed04aa9b06802e.camel@intel.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: C2B561C001A X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: qtfig4rutiriwfdenm8w1r8xwmckfh6g X-HE-Tag: 1675154794-975147 X-HE-Meta: U2FsdGVkX19FA0Fgns2CZwZLXtp1w4IKCVDadEtAw/rFmXgljuDrClX/gKDgpNj2IHa2o8/xtGm3RbnIZ5hRfcKik2bwn2LZjI7vJbZVep0tMh70KJPDrw6BHlsUkQJqMVZsJs0NJE9gFET4qBLS2PTBwgdl+RYXtfzoAJx1OKiACKGtJ5jo8Kz34eLhpUCGmuqcFnFD+yE6IhgVNQQk3r7z701pOobQsSf6EDwSu9L/UA9W4CEWAXP5ZminfX7v5PBzuVFcKSqTRrguI506SUjqR2AaXXblG+BmnG7GwtGXgisTLmGVX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WtUhXNYuvTKORNjQD7cy7fsHGCpZ9iwf+2kkRJ2eENR4cXoOjXpra3swoMwaVEZRDu0POwreOLPIGPZuzYiHO1AzOr33sWakV0rOKDDKSR 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: On 28.01.23 01:51, Edgecombe, Rick P wrote: > On Fri, 2023-01-27 at 17:12 +0100, David Hildenbrand wrote: >> On 26.01.23 21:19, Edgecombe, Rick P wrote: >>> On Thu, 2023-01-26 at 09:46 +0100, David Hildenbrand wrote: >>>> On 26.01.23 01:59, Edgecombe, Rick P wrote: >>>>> On Wed, 2023-01-25 at 10:43 -0800, Rick Edgecombe wrote: >>>>>> Thanks for your comments and ideas here, I'll give the: >>>>>> pte_t pte_mkwrite(struct vm_area_struct *vma, pte_t pte) >>>>>> ...solution a try. >>>>> >>>>> Well, it turns out there are some pte_mkwrite() callers in >>>>> other >>>>> arch's >>>>> that operate on kernel memory and don't have a VMA. So it >>>>> needed a >>>>> new >>>> >>>> Why not pass in NULL as VMA then and document the semantics? The >>>> less >>>> similarly named but slightly different functions, the better :) >>> >>> Hmm. The x86 and generic versions should probably have the same >>> semantics, so then if you pass a NULL, it would do a regular >>> pte_mkwrite() I guess? >>> >>> I see another benefit of requiring the vma argument, such that raw >>> pte_mkwrite()s are less likely to appear in core MM code. But I >>> think >>> the NULL is awkward because it's not obvious, to me at least, what >>> the >>> implications of that should be. >>> >>> So it will be confusing to read in the NULL cases for the other >>> archs. >>> We also have some warnings to catch miss cases in the PTE tear down >>> code, so the scenario of new code accidentally marking shadow stack >>> PTEs as writable is not totally unchecked. >>> >>> The three functions that do slightly different things are: >>> >>> pte_mkwrite(): >>> Makes a PTE conventionally writable, only takes a PTE. Very clear >>> that >>> it is a low level helper and what it does. >>> >>> maybe_mkwrite(): >>> Might make a PTE writable if the VMA allows it. >>> >>> pte_mkwrite_vma(): >>> Makes a PTE writable in a specific way depending on the VMA >>> >>> I wonder if the name pte_mkwrite_vma() is maybe just not clear >>> enough. >>> It takes a VMA, yes, but what does it do with it? >>> >>> What if it was called pte_mkwrite_type() instead? Some arch's have >>> additional types of writable memory and this function creates them. >>> Of >>> course they also have the normal type of writable memory, and >>> pte_mkwrite() creates that like usual. Doesn't it seem more >>> readable? >> >> The issue is, the more variants we provide the easier it is to make >> mistakes and introduce new buggy code. >> >> It's tempting to simply use pte_mkwrite() and call it a day, where >> people actually should use pte_mkwrite_vma(). >> >> Then, they at least have to investigate what to do about the second >> VMA >> parameter. > > Ok, I'll give it a spin. So far it looks ok. The downside is the giant > tree-wide pte_mkwrite() signature change, but once that is over with > there are other advantages. Like getting rid of maybe_mkwrite()'s > awareness of shadow stack so the logic is more centralized. Please let > me know if you don't feel comfortable with a suggested-by credit tag. Sure ... but I reconsidered :) Maybe there is a cleaner way to do it and avoid the "NULL" argument. What about having (while you're going over everything already): pte_mkwrite(pte, vma) pte_mkwrite_kernel(pte) The latter would only be used in that arch code where we're working on kernel pgtables. We already have pte_offset_kernel() and pte_alloc_kernel_track(), so it's not too weird. -- Thanks, David / dhildenb