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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDF78C38142 for ; Mon, 23 Jan 2023 09:51:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231724AbjAWJvL (ORCPT ); Mon, 23 Jan 2023 04:51:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230371AbjAWJvK (ORCPT ); Mon, 23 Jan 2023 04:51:10 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D57411422C for ; Mon, 23 Jan 2023 01:50:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674467418; 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=kSYxORSo5fJ20pO0AdfHiuiQJWJRfHcLYdctAQzz20k=; b=H/R+ghhrhsiL4pY11BZXl3daqHx8WZF9OqyOcYz/9Wxd8mXnL9Y7sqFbqcmQ/lezkZ/8f3 tD3l0mZA8vkuxHZHLPBJ3suL4i0PL9YXfGxIODHHD3mnT746dnerwFpkT9TY5EnSNXAwZf NeGlMVtwhjznBVEuGxvOQqEED+TcBQg= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-96-sWePbVBYP5GLR-ckrTM4xQ-1; Mon, 23 Jan 2023 04:50:16 -0500 X-MC-Unique: sWePbVBYP5GLR-ckrTM4xQ-1 Received: by mail-wr1-f70.google.com with SMTP id e29-20020adf9bdd000000b002bb0d0ea681so1851176wrc.20 for ; Mon, 23 Jan 2023 01:50:16 -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:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=kSYxORSo5fJ20pO0AdfHiuiQJWJRfHcLYdctAQzz20k=; b=0fgY/7yhRrT4vaVlMGGUz48weZel5Iohd7IBjDupiHYYNX4oqFZvHdaQVjkMiVPKIx keLsmdhVxHUKDGYwYOTQVtv3cBiQ0ievXZeGVKVvwRl4GMoGuLBc9r2JgvaolXEbPsku bwpcQBRb/cvgXuU4OcFiJ4igQF3UX6uGnhdH6zCXqwqxhHhBebJkdhyHUTFdCUt3KPLe rKTS697hirm39lXYtGoIGNaTKmFstBc0cyDmKDv0Fv5O/6N0kjXu+aaB39jrQvEDucyr gjqbuXfBU1wbWm8noArdRZl3dBnTJArvMYV1sGnHJTeqDHJ2wuhyHZJDA5pVLuu5FRmZ jmjA== X-Gm-Message-State: AFqh2kqSGxf4xzQGUszn01bTQJsYcQx5xCCBVLMmrT93P6TL4IZj4pxl b39jwvnp4UmUcx6ABUx/mw+pF2JfcTNCsvbQRrUTMqGng7P9WB1TonEFHYyzA7Rxn5/g62aLmmY x58AxkdfYbT2ojO8sCqtQ X-Received: by 2002:a05:600c:3b1e:b0:3cf:497c:c4f5 with SMTP id m30-20020a05600c3b1e00b003cf497cc4f5mr23576031wms.13.1674467415679; Mon, 23 Jan 2023 01:50:15 -0800 (PST) X-Google-Smtp-Source: AMrXdXs9yQJkaBPo8s7D1+JPWykvhgcJBeDr0ywpOXES22KIpL3qQHqi+WIix769Us7mHmdo/CB66w== X-Received: by 2002:a05:600c:3b1e:b0:3cf:497c:c4f5 with SMTP id m30-20020a05600c3b1e00b003cf497cc4f5mr23576006wms.13.1674467415336; Mon, 23 Jan 2023 01:50:15 -0800 (PST) Received: from ?IPV6:2003:cb:c704:1100:65a0:c03a:142a:f914? (p200300cbc704110065a0c03a142af914.dip0.t-ipconnect.de. [2003:cb:c704:1100:65a0:c03a:142a:f914]) by smtp.gmail.com with ESMTPSA id p1-20020a1c7401000000b003b3307fb98fsm10069782wmc.24.2023.01.23.01.50.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 23 Jan 2023 01:50:14 -0800 (PST) Message-ID: <7f63d13d-7940-afb6-8b25-26fdf3804e00@redhat.com> Date: Mon, 23 Jan 2023 10:50:13 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 Content-Language: en-US To: Rick Edgecombe , x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com Cc: Yu-cheng Yu References: <20230119212317.8324-1-rick.p.edgecombe@intel.com> <20230119212317.8324-19-rick.p.edgecombe@intel.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v5 18/39] mm: Handle faultless write upgrades for shstk In-Reply-To: <20230119212317.8324-19-rick.p.edgecombe@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-doc@vger.kernel.org On 19.01.23 22:22, Rick Edgecombe wrote: > The x86 Control-flow Enforcement Technology (CET) feature includes a new > type of memory called shadow stack. This shadow stack memory has some > unusual properties, which requires some core mm changes to function > properly. > > Since shadow stack memory can be changed from userspace, is both > VM_SHADOW_STACK and VM_WRITE. But it should not be made conventionally > writable (i.e. pte_mkwrite()). So some code that calls pte_mkwrite() needs > to be adjusted. > > One such case is when memory is made writable without an actual write > fault. This happens in some mprotect operations, and also prot_numa faults. > In both cases code checks whether it should be made (conventionally) > writable by calling vma_wants_manual_pte_write_upgrade(). > > One way to fix this would be have code actually check if memory is also > VM_SHADOW_STACK and in that case call pte_mkwrite_shstk(). But since > most memory won't be shadow stack, just have simpler logic and skip this > optimization by changing vma_wants_manual_pte_write_upgrade() to not > return true for VM_SHADOW_STACK_MEMORY. This will simply handle all > cases of this type. > > Cc: David Hildenbrand > Tested-by: Pengfei Xu > Tested-by: John Allen > Signed-off-by: Yu-cheng Yu > Reviewed-by: Kirill A. Shutemov > Signed-off-by: Rick Edgecombe > --- Instead of having these x86-shadow stack details all over the MM space, was the option explored to handle this more in arch specific code? IIUC, one way to get it working would be 1) Have a SW "shadowstack" PTE flag. 2) Have an "SW-dirty" PTE flag, to store "dirty=1" when "write=0". pte_mkwrite(), pte_write(), pte_dirty ... can then make decisions based on the "shadowstack" PTE flag and hide all these details from core-mm. When mapping a shadowstack page (new page, migration, swapin, ...), which can be obtained by looking at the VMA flags, the first thing you'd do is set the "shadowstack" PTE flag. -- Thanks, David / dhildenb