Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3578408rwb; Mon, 3 Oct 2022 17:59:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM74QibxEG5/bjyRVBoRSm0DvHMyawPsim0lHORRTdlyQHSgnS4Qr5ZEXGl/kybMD7fCBUU4 X-Received: by 2002:a17:907:2e0d:b0:77e:999f:dea3 with SMTP id ig13-20020a1709072e0d00b0077e999fdea3mr16650074ejc.317.1664845158160; Mon, 03 Oct 2022 17:59:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664845158; cv=none; d=google.com; s=arc-20160816; b=hcC6zSe6GRSWMxEpMc++lO6QsSpfS9kwwL+iqDoSMA7V95M7HiXwQCXpaG3vX8gmd8 8ok7HJS12X+3HC/BmcN3PYjny8ILGgyyE670YSWtcni3BRiA/dDGoryy8nDR1gULEhe3 15558X7UpRIgLJnu2cf229pd++2qLy+udQFGTMn3br02sOTC/+YXZbuelRcaCutpSGJ3 2z0Kmyt46XGC9j74df4ir2OoAbQm5VVK7nfUnkDP8MIRQHfCIOiJJDB2ZfalLPxuDdn/ TDEQ7rguFeUy00Hog+HAd5Gm54mZTDPe9EuXdgjl9V6prnV2btAFMX/lJK3/X3QaRiDC Hopw== 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=3q++8wCYsHAJwCqlE3FugCt33Ln5kkLpxe2fyPzpKGo=; b=ls7hRW7eSOm3rEXaHlO7XZc81W+w8NeSSDAtvyCLOf7CzesAcGIMj8ihKqZ1zDEXYn QxTcY+MHUWHd7tjQj5n75phHdRnFFCqxv7dBxNs9cGE0xXioAHn4KNkL5eBFyKQwOvD5 Z1Cj/eSAIKeVU+5fNE4orjdAzhiEFTO4PF3Tx8E1pPY4Em9co2QK7sSol0eV+pBfWdRi UxvOK9qrIcioAYitPkNd8QfvOpBD9vlV9A91dzt3ZqK+Ka6Os5F4lUgl/x07tP2kCrYc SfxQWU8KOtn5Azx2pVxdvX1EsrCdWi637/6tLSNWmrEGJla6PmvFnSzmYPlc+ZxoJLNI 9xNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=nRPEqYmV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a1709063f9400b00782f3e3bb71si8227944ejj.912.2022.10.03.17.58.51; Mon, 03 Oct 2022 17:59:18 -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=@intel.com header.s=Intel header.b=nRPEqYmV; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229854AbiJCXxQ (ORCPT + 99 others); Mon, 3 Oct 2022 19:53:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229495AbiJCXxN (ORCPT ); Mon, 3 Oct 2022 19:53:13 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9335523BE3; Mon, 3 Oct 2022 16:53:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664841192; x=1696377192; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=XsbQqB1kOV5HDsgsc4ONdzxsJU1pLr3Pc/WAWDj/ozo=; b=nRPEqYmVaE0MM0Ksv7Q55Z32YUCsu5AGy1PuPLcRRvM2Tb4fKqko0j5z QFrHXgJmhWTCNSMvXl0vIGEz2csaqMX/vf/k/ecibZeexVXa3Wd8/63r0 69o7gYYP+9c8A2NjUfot0OpL6tpGRuWNCFSxtUzV12Q3V427Itpsa2PjI YNeESS3tOpPqiZm1Qq7ThsviLl0SOnZreH8vwo/8Ec9chI7s0Pmm31jzI 3WXwUsG1vRVNEGLtM86odAq5L2ICxBom2CpOY1zrBHfGhDSEU50icqWho b5n2q1+QO5Y5e8mbkPMwFwJHAc2fZao1WqqP8CRf6XMTie7+asLWpF2kL g==; X-IronPort-AV: E=McAfee;i="6500,9779,10489"; a="366887311" X-IronPort-AV: E=Sophos;i="5.93,366,1654585200"; d="scan'208";a="366887311" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2022 16:53:11 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10489"; a="749189186" X-IronPort-AV: E=Sophos;i="5.93,366,1654585200"; d="scan'208";a="749189186" Received: from bandrei-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.37.219]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2022 16:53:03 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 319D8104CE4; Tue, 4 Oct 2022 02:53:00 +0300 (+03) Date: Tue, 4 Oct 2022 02:53:00 +0300 From: "Kirill A . Shutemov" 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 , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , 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: <20221003235300.zkf6lfemd7kyl47z@box.shutemov.name> 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.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 Maybe take opportunity to move it to ? It is really not a place for the helper. -- Kiryl Shutsemau / Kirill A. Shutemov