Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp2290737pxb; Wed, 9 Feb 2022 15:18:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJw57ZnTKAIQ+9bUplGRAUQjLMkMvNLR7yoUvtH6ZAcSwNxCdjEX4YfwmNkk77uLAXQBZPr2 X-Received: by 2002:a62:6d01:: with SMTP id i1mr4713289pfc.45.1644448720786; Wed, 09 Feb 2022 15:18:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644448720; cv=none; d=google.com; s=arc-20160816; b=wzS8w7HV1BWWRFTMDQ7HA6LmEJgdDcBftQum5hdxUtQYZUriPSZ8tT61pzR7Ay2Yb9 FMLBLfaEhGb98F0CVyKSuqBH7bm7mfJh3MDh/lzwvOiqpnvGIePnuYzrTgUW4VisK/dr 799AlUa8C4YNyOOlT10ejamIjlCRzXDvchAWqy50BJ6VY48pTsOZzvbRKWBpOOljxsc+ /2angjHaszsOZMg7VD7umPKAaPPzcSEvoGhtuDttdLO7DbGW/DmdxXRtf3mvtyOUrw8q sNpspevbv/GJqA+cYz65jJOfnldDReTUK3mr5l/XqYPn73kvr35JobRnt/sELenj+6W/ FrgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=eYTUUrp8ujckO+6KO5AJo2dfweEgW06+o2WasHyczKI=; b=qkhBC3aKPHLFpTWOGBLa67uWs2ztOHtMetIEJyvInIK1GLFecpIEqlCbwRxEU1JPAD 8Y+irmiCrOYNIJ3W/+UBovtdHjIaYQRJu31M8tMAEa/xOxErT7IxgVDBDPSifspzO4c0 MXHjJBB2xeHJeMSciawMNTBjU5waCit4Bmk9qhgqAldYoVpA+EQsa1g2bXQts7o4zuBm RvGF83Llk6D1VImEitQggh9VAFh1SAo3fEMD8otlEsM3Me4zH847BcH66yZLa6x5nEZi i60H6w401WHAC3ZjMKUvohB3nSGveMVwlvALnOJukjS15e9H5tcFaF2Fa5PhZcGLeAI4 zJIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MkV2o6ff; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id m18si6032393pjz.179.2022.02.09.15.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Feb 2022 15:18:40 -0800 (PST) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MkV2o6ff; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 94506E0536CD; Wed, 9 Feb 2022 15:16:06 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233135AbiBIVQ5 (ORCPT + 99 others); Wed, 9 Feb 2022 16:16:57 -0500 Received: from gmail-smtp-in.l.google.com ([23.128.96.19]:43552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233085AbiBIVQz (ORCPT ); Wed, 9 Feb 2022 16:16:55 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A7FBC0DE7F8; Wed, 9 Feb 2022 13:16:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644441418; x=1675977418; h=message-id:date:mime-version:to:cc:references:from: subject:in-reply-to:content-transfer-encoding; bh=aXGhdB7/S/Sfe6z0D5nuv8iSXKIxW6oQrnd4HjbGcpI=; b=MkV2o6ffagkn8+j7qQfTAcU1RIrMB6PMn6ZLsgM5zCEOEDlIgk8LmE/M xyP4bpHsdYx+o/7aKS8DvdV1vckhScr4FvZzueqmKPyyJX6hGyb6ZJMeh AP0ZfxSzP6b8h+VElyb++GaF4EbGpRV3KJRGUShRTMtPvUkgc/W3A/L8B R3VWD61HDGqbBzEC3NXptjHbMYcDRrld2WBJeQqsqnAyS5A1r43W4BO1f xy5t5tPqgJmcRrutbNqpreoghiMYO5VfxjKdtSBazcbxga5QfhW0KKsmj aarb5lKmjbZQi7gGjIs8hqiJCb1vc+n3G2gmgbLgIgCkpQZl8r5CygfIg Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10253"; a="249284114" X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="249284114" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 13:16:53 -0800 X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="585721023" Received: from sanvery-mobl.amr.corp.intel.com (HELO [10.212.232.139]) ([10.212.232.139]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 13:16:52 -0800 Message-ID: Date: Wed, 9 Feb 2022 13:16:49 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.5.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 , "Ravi V . Shankar" , Dave Martin , Weijiang Yang , "Kirill A . Shutemov" , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com Cc: Yu-cheng Yu References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> <20220130211838.8382-17-rick.p.edgecombe@intel.com> From: Dave Hansen Subject: Re: [PATCH 16/35] x86/mm: Update maybe_mkwrite() for shadow stack In-Reply-To: <20220130211838.8382-17-rick.p.edgecombe@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 First of all, that changelog doesn't really explain the problem. It's all background and no "why". *Why* does maybe_mkwrite() take a VMA? What's the point? > #endif /* _ASM_X86_PGTABLE_H */ > diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c > index 3481b35cb4ec..c22c8e9c37e8 100644 > --- a/arch/x86/mm/pgtable.c > +++ b/arch/x86/mm/pgtable.c > @@ -610,6 +610,26 @@ int pmdp_clear_flush_young(struct vm_area_struct *vma, > } > #endif > > +pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) > +{ > + if (vma->vm_flags & VM_WRITE) > + pte = pte_mkwrite(pte); > + else if (vma->vm_flags & VM_SHADOW_STACK) > + pte = pte_mkwrite_shstk(pte); > + return pte; > +} First, this makes me wonder why we need pte_mkwrite() *AND* pte_mkwrite_shstk(). Is there a difference in their behavior that matters? Second, I don't like the copy-and-paste to make an arch-specific "hook" for a function. This is a very good way to ensure that arch code and generic code fork and accumulate separate bugs. I'd much rather have this do (in generic code): pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) { if (vma->vm_flags & VM_WRITE) pte = pte_mkwrite(pte); pte = arch_maybe_mkwrite(pte, vma); return pte; +} Actually, is there a reason the generic code could not even just add: if (vma->vm_flags & VM_ARCH_MAYBE_MKWRITE_MASK) pte = arch_maybe_mkwrite(pte, vma); or heck even just the x86-specific code itself: if (vma->vm_flags & VM_SHADOW_STACK) pte = pte_mkwrite_shstk(pte); with a stub defined for pte_mkwrite_shstk()? In the end, it's just a question of whether the generic code wants something to say "arch" or "shstk". But, I don't think we need a forked x86 copy of these functions. > diff --git a/include/linux/mm.h b/include/linux/mm.h > index 311c6018d503..b3cb3a17037b 100644 > --- a/include/linux/mm.h > +++ b/include/linux/mm.h > @@ -955,12 +955,14 @@ void free_compound_page(struct page *page); > * pte_mkwrite. But get_user_pages can cause write faults for mappings > * that do not have writing enabled, when used by access_process_vm. > */ > +#ifndef maybe_mkwrite maybe_mkwrite is defined in asm/pgtable.h. Where is the #include? > static inline pte_t maybe_mkwrite(pte_t pte, struct vm_area_struct *vma) > { > if (likely(vma->vm_flags & VM_WRITE)) > pte = pte_mkwrite(pte); > return pte; > } > +#endif > > vm_fault_t do_set_pmd(struct vm_fault *vmf, struct page *page); > void do_set_pte(struct vm_fault *vmf, struct page *page, unsigned long addr); > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 406a3c28c026..2adedcfca00b 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -491,12 +491,14 @@ static int __init setup_transparent_hugepage(char *str) > } > __setup("transparent_hugepage=", setup_transparent_hugepage); > > +#ifndef maybe_pmd_mkwrite > pmd_t maybe_pmd_mkwrite(pmd_t pmd, struct vm_area_struct *vma) > { > if (likely(vma->vm_flags & VM_WRITE)) > pmd = pmd_mkwrite(pmd); > return pmd; > } > +#endif > > #ifdef CONFIG_MEMCG > static inline struct deferred_split *get_deferred_split_queue(struct page *page)