Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp809905rwi; Fri, 14 Oct 2022 08:52:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6b/zBUZhumrZ5+n73jYQKHEQafdPbssMhcIPWmdNl8FWwsEitvZu5ZuAZA0WCq7v5D82ic X-Received: by 2002:a17:907:3e1b:b0:78d:ccd0:c9f8 with SMTP id hp27-20020a1709073e1b00b0078dccd0c9f8mr4055866ejc.705.1665762732525; Fri, 14 Oct 2022 08:52:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665762732; cv=none; d=google.com; s=arc-20160816; b=KD8ct33YeCXMgaelsvbbadIyXgE9kkPxP6Jn1itQp5FceeNZrFUF3eIDBSraC7BSYX 4GrHGyBqsYVFW+lmQvnuaa3DBoMM8e4LTWdBqeJ8Q6ZcFhZmBQ4zYlTM/I+xUbKeFXmL MU70LnyC2tAwYdUH+1P6XGzU1NbyhSJhoU6nNngipO4UAUrgLsonZMOwD4V5tACmK2u9 Zi642MYztsDD5hdZ7yzY8yHERtk585YBFT0WiRAk99R1Icgf+6+cgjspTRsi1FVCd71y elpn1R3e4+MREi0COR/OE8kBDWx/k6nG4bXaZ+jB6FeU5/AuyPWLy9aAW2IJi+Wh3QO5 Qqog== 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=tcM8guTF51y4dORNbVL0TNPgqKXsDWO1cxQKagb6RpQ=; b=XO9aKhwdEcGHRmkyKss/Lg8uMC3Q0F9NtSnvC3EbVc58B9tNJSOTD+KZYbMBZM7Kj+ MEVSaBOxhzn82SH1LdjNMktNevjv+x8ecjNrmIIUea8dnfDSYc0Th0VDCQpQrEDDboZw H+9OiWko0UIqHFFzZOQehmgcNGvnQsBen5vLff1TbUKozZE5fOmrqLCaRAJXnA8iGcsQ SIGYbAz4z1PorytzfPxZZEra/0vd1iQrVrFOpsbbYLP0pW1vsY+LHji139Qfp3wHAYjS RloMi7ttC+vOVG2tAxN4Mylvqm+RPxg8B/TFgPW8xTeuDYkjky9M0//n8dHsYwslwYT2 J6Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b="WVap/vaD"; 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 nc23-20020a1709071c1700b00779f8e7ec5bsi2849951ejc.42.2022.10.14.08.51.44; Fri, 14 Oct 2022 08:52:12 -0700 (PDT) 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="WVap/vaD"; 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 S230456AbiJNPd7 (ORCPT + 99 others); Fri, 14 Oct 2022 11:33:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbiJNPdj (ORCPT ); Fri, 14 Oct 2022 11:33:39 -0400 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 E142B9B86E; Fri, 14 Oct 2022 08:33:18 -0700 (PDT) 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=tcM8guTF51y4dORNbVL0TNPgqKXsDWO1cxQKagb6RpQ=; b=WVap/vaDDQsosYCxpzXStdd50N Xk2922O8Nbnqsjsb7+6hUodsPGVCrgVKrgsn6NfJbcuv4mwas/y+srH7BfoI2LqFrwhgi10jfsRA5 BF5HbdvfzMysaPdmw34TGJWtYFtfTuuYzrMdn5E4wZaR/0h+CS+5Lnjj8/qEz9fk+crwilALA5lcd 9vyrq/l1kfFZRojAVxnCzyxStxB5YJ4n7DHWVFx7y6nbeh/ctE5/IXQaj3VZTKyKCpdrmYIup4hIp AsBs24qOaZHKyxFCm7DrkIKq/qg/Idd5PdX88EJkUS3LBwmoVyLOnJfA5QcfscgRUwmW1tqkjEaWb ymkHe8ig==; 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 1ojMfw-003RUm-BQ; Fri, 14 Oct 2022 15:32:40 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 248EA30004F; Fri, 14 Oct 2022 17:32:39 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0D9852C1B0A4D; Fri, 14 Oct 2022 17:32:39 +0200 (CEST) Date: Fri, 14 Oct 2022 17:32:38 +0200 From: Peter Zijlstra To: Rick Edgecombe Cc: 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 , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, Yu-cheng Yu Subject: Re: [PATCH v2 16/39] x86/mm: Update maybe_mkwrite() for shadow stack Message-ID: References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-17-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220929222936.14584-17-rick.p.edgecombe@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 Thu, Sep 29, 2022 at 03:29:13PM -0700, Rick Edgecombe wrote: > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 8cd413c5a329..fef14ab3abcb 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -981,13 +981,25 @@ void free_compound_page(struct page *page); > * servicing faults for write access. In the normal case, do always want > * pte_mkwrite. But get_user_pages can cause write faults for mappings > * that do not have writing enabled, when used by access_process_vm. > + * > + * If a vma is shadow stack (a type of writable memory), mark the pte shadow > + * stack. > */ > +#ifndef maybe_mkwrite > static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) > { > - if (likely(vma->vm_flags & VM_WRITE)) > + if (!(vma->vm_flags & VM_WRITE)) > + goto out; > + > + if (vma->vm_flags & VM_SHADOW_STACK) > + pte = pte_mkwrite_shstk(pte); > + else > pte = pte_mkwrite(pte); > + > +out: > return pte; > } > +#endif Why the #ifndef guard? There is no other implementation, nor does this patch introduce one. Also, wouldn't it be simpler to write it like: static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) { if (!(vma->vm_flags & VM_WRITE)) return pte; if (vma->vm_flags & VM_SHADOW_STACK) return pte_mkwrite_shstk(pte); return pte_mkwrite(pte); } ? (idem for the pmd version etc..)