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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 06576C433F5 for ; Wed, 9 Feb 2022 21:51:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2A2286B0073; Wed, 9 Feb 2022 16:51:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2525B6B0075; Wed, 9 Feb 2022 16:51:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 119C36B0078; Wed, 9 Feb 2022 16:51:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0122.hostedemail.com [216.40.44.122]) by kanga.kvack.org (Postfix) with ESMTP id 006AD6B0073 for ; Wed, 9 Feb 2022 16:51:50 -0500 (EST) Received: from smtpin10.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 72ED4824C423 for ; Wed, 9 Feb 2022 21:51:50 +0000 (UTC) X-FDA: 79124589180.10.6683235 Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by imf02.hostedemail.com (Postfix) with ESMTP id 6ACFF80006 for ; Wed, 9 Feb 2022 21:51:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644443509; x=1675979509; h=message-id:date:mime-version:to:cc:references:from: subject:in-reply-to:content-transfer-encoding; bh=2XmQo/8+05nnCFD6IB5G6G1lj5TYd6uWzLLIRuhEalQ=; b=YnK5yJQO8612TRutkKVeL32MIqnzX1CcICZ2mHB6jnnuTCVtwseHH8nO MFSSy6/fkEoIdNbLgr248Et8SC3qjiLxc8bk8vHcdEkYqP5wxZCeV1lNN NmGZuO1sF43oUpOgy3holY0pROAdFQ/56xpv4E/YzFs5W3JhAaxR+HBt3 ivej5mZ+yideGKV4QslYpyYrsDqD0cnsMZHvfl89IIsv17iaPvPPYDhcn 1tSfa3cGeNL5lSqBYOXKPbZ/0ApXRbm9e+r089FYd7ClqGN/8Hd4VIipu 1OeXN6jBOMBlimY+sedf7ZccCHvWqTjZa8HQdmx9MiwZm95en1WI6ef2w A==; X-IronPort-AV: E=McAfee;i="6200,9189,10253"; a="229994561" X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="229994561" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2022 13:51:47 -0800 X-IronPort-AV: E=Sophos;i="5.88,356,1635231600"; d="scan'208";a="585733999" 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:51:45 -0800 Message-ID: <8065c333-0911-04a2-f91e-7c2e0cc7ec51@intel.com> Date: Wed, 9 Feb 2022 13:51:42 -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-18-rick.p.edgecombe@intel.com> From: Dave Hansen Subject: Re: [PATCH 17/35] mm: Fixup places that call pte_mkwrite() directly In-Reply-To: <20220130211838.8382-18-rick.p.edgecombe@intel.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 6ACFF80006 X-Stat-Signature: hik3wbssrt7ehfpxujch9mtnjjjujtn3 X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=YnK5yJQO; spf=none (imf02.hostedemail.com: domain of dave.hansen@intel.com has no SPF policy when checking 192.55.52.151) smtp.mailfrom=dave.hansen@intel.com; dmarc=pass (policy=none) header.from=intel.com X-Rspamd-Server: rspam05 X-HE-Tag: 1644443509-695724 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 1/30/22 13:18, Rick Edgecombe wrote: > - do_anonymous_page() and migrate_vma_insert_page() check VM_WRITE directly > and call pte_mkwrite(), which is the same as maybe_mkwrite(). Change > them to maybe_mkwrite(). Those look OK. > - In do_numa_page(), if the numa entry was writable, then pte_mkwrite() > is called directly. Fix it by doing maybe_mkwrite(). Make the same > changes to do_huge_pmd_numa_page(). This is another "what", not "why" changelog. This change puzzles me. *Why* is this needed? It sounds like pte_mkwrite() doesn't work for shadow stack PTEs. Let's say that explicitly. I also this this is ab/misuse of maybe_mkwrite(). The shadow stack VMA *REQUIRES* PTEs with Dirty=1. There's no *maybe* about it. The rest of this is essentially a hack to get VM_SHADOW_STACK-required bits into the PTE. We have a place where we store those VMA-required bits: vma->vm_page_prot. Look at how we store the pkey bits in there for instance. Let's say we set _PAGE_DIRTY in vma->vm_page_prot. We'd come into do_anonymous_page() for instance and do this: > entry = mk_pte(page, vma->vm_page_prot); <--- PTE is Write=0,Dirty=1 Yay! > entry = pte_sw_mkyoung(entry); > if (vma->vm_flags & VM_WRITE) <--- False, skip the pte_mkwrite() > entry = pte_mkwrite(pte_mkdirty(entry)); In other words, it "just works" because shadow stack VMAs don't have VM_WRITE set. I think the other VM_WRITE checks would be fine too, although I'm unsure about the change_page_attr() one.