Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp443114rwb; Wed, 16 Nov 2022 03:02:11 -0800 (PST) X-Google-Smtp-Source: AA0mqf6yLX7Ih7S+2OFKnzJ4sWdTs7TQ1yeSVHOdZalrJInEuwSxchnZb+NhaaN2X2rNSHAbND2D X-Received: by 2002:a05:6402:35c4:b0:462:fb18:3b45 with SMTP id z4-20020a05640235c400b00462fb183b45mr18383272edc.243.1668596530790; Wed, 16 Nov 2022 03:02:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668596530; cv=none; d=google.com; s=arc-20160816; b=hVoYCX0qMJnvVdOarQchpOGedFQfNO8Npg2BW9LEvXSi/G76jya/DBhcYrKMQelgqW mtEtgGzkpksHW/yjid4zThTwuvjd0glypMu9ehWRgN5DJycVO8kJmkcFZw1OUHc9Qlai F+YUW1KG0ArZKvjd1XYZSYKEkG7uGYUIUj4C8CefwC47mGj3/ZAUkiunzcR48EINwuIz CpCBaTFikhB41i7eDqwk6FFDjXIdD1n+owr135vxppKobQ+YgM7BRVPsnYrlSooSW95D LcANGHk9v/d7lSX433ScMqrpBSnUs+Eoh/tYQ17aRPfE5n/N9oOxUUoG1veojFCIyKFj VndA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=IP43t3hJu1Ut6R9gno8nfJ5M4E7h1wkQRd32HTSGUjo=; b=JzEDJU+oHCfRgCYOcPBmDxSVoU0l/NFEiGTERFi4c6szKoZQ0FAjnf0WjImaY1aLPH WHByA0EERzdCd9SMFU1ezudhT7HrrK5h5FZSBKD46zP1WMedif9m94xZlAjm3zxsZZ0P KNgvWDh9stYO4g2Y0RRmGVLUhmbS3UbqZKYmtlA+hb3aOYDCIVYPEDDeOFLoYHmDwR57 K8uUxxZWSHs0adMZjm8BIPZFQGOdRhZ1ZWj4+Mm0L5+6MdHbeQRi38ZLve6pMBzWs9bL ND8wPcKkAQS4LaAocLkOaS7uwUbq7Xn0QuPVrI3ibkiSLKvyU0hH4vdXJ2MByCZwlZTr J3kA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=cwGxlcmq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js6-20020a17090797c600b007ad8218ad7fsi16103089ejc.379.2022.11.16.03.01.40; Wed, 16 Nov 2022 03:02:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=cwGxlcmq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232680AbiKPKKa (ORCPT + 91 others); Wed, 16 Nov 2022 05:10:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231952AbiKPKK1 (ORCPT ); Wed, 16 Nov 2022 05:10:27 -0500 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 94B7D1A825; Wed, 16 Nov 2022 02:10:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; 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=IP43t3hJu1Ut6R9gno8nfJ5M4E7h1wkQRd32HTSGUjo=; b=cwGxlcmqkrn87V+pOU9TIN5gsZ k8k+ZoTpU4HiUzsqFp0EdEccYC9aLsFjSnFJKHVZkUssN+8m1CajV6ccnmwTQLTzAvE3fh0Eg9UWj 8Vjq2DE8gsMlpoe3bNrOPKMnoimSk4Hy4A1AembykPKeRTvnNsVwJrqZ5S5Rq1xy2QrGvR0VQpvzR aqBiXKrgeyXbwJA2FSEv5araqwycTv9CHOUplwwq23PBbX+jaY3gKF6bBpvmm1ZwIvXGV37I2R7kL 9eUIxURMM9d6ZtfgZRR07+9oQGfYZUe+x5IjIJAFy3DxvvCkM9Tm7pQyMPG0BKjuL9SeQ5YQCqn1Q srVTO45w==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ovFMY-001GVE-G6; Wed, 16 Nov 2022 10:09:46 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E8DE730002E; Wed, 16 Nov 2022 11:09:43 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 8B0392B5E08EB; Wed, 16 Nov 2022 11:09:43 +0100 (CET) Date: Wed, 16 Nov 2022 11:09:43 +0100 From: Peter Zijlstra To: "Edgecombe, Rick P" Cc: "bsingharora@gmail.com" , "hpa@zytor.com" , "Syromiatnikov, Eugene" , "rdunlap@infradead.org" , "keescook@chromium.org" , "Yu, Yu-cheng" , "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" , "bp@alien8.de" , "oleg@redhat.com" , "hjl.tools@gmail.com" , "Yang, Weijiang" , "Lutomirski, Andy" , "jamorris@linux.microsoft.com" , "arnd@arndb.de" , "tglx@linutronix.de" , "pavel@ucw.cz" , "mike.kravetz@oracle.com" , "x86@kernel.org" , "linux-doc@vger.kernel.org" , "rppt@kernel.org" , "john.allen@amd.com" , "mingo@redhat.com" , "Shankar, Ravi V" , "corbet@lwn.net" , "linux-kernel@vger.kernel.org" , "linux-api@vger.kernel.org" , "gorcunov@gmail.com" , "akpm@linux-foundation.org" Subject: Re: [PATCH v3 15/37] x86/mm: Check Shadow Stack page fault errors Message-ID: References: <20221104223604.29615-1-rick.p.edgecombe@intel.com> <20221104223604.29615-16-rick.p.edgecombe@intel.com> <2766aedef0780f03b81ea7dfea42dffb328e21f1.camel@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <2766aedef0780f03b81ea7dfea42dffb328e21f1.camel@intel.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 15, 2022 at 11:13:34PM +0000, Edgecombe, Rick P wrote: > When a page becomes COW it changes from a shadow stack permissioned > page (Write=0,Dirty=1) to (Write=0,Dirty=0,CoW=1), which is simply > read-only to the CPU. When shadow stack is enabled, a RET would > normally pop the shadow stack by reading it with a "shadow stack read" > access. However, in the COW case the shadow stack memory does not have > shadow stack permissions, it is read-only. So it will generate a fault. > > For conventionally writable pages, a read can be serviced with a read > only PTE, and COW would not have to happen. But for shadow stack, there > isn't the concept of read-only shadow stack memory. If it is shadow > stack permissioned, it can be modified via CALL and RET instructions. > So COW needs to happen before any memory can be mapped with shadow > stack permissions. > > Shadow stack accesses (read or write) need to be serviced with shadow > stack permissioned memory, so in the case of a shadow stack read > access, treat it as a WRITE fault so both COW will happen and the write > fault path will tickle maybe_mkwrite() and map the memory shadow stack. ACK.