Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp620116pxb; Tue, 1 Feb 2022 07:08:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJw4sSKO/ewTy7Y6g5LB3OjjB5BCZxCTDiIzAOH21GIPJYrRrgrKA5N/PrOLwvESi6JvsMjb X-Received: by 2002:a17:906:6b12:: with SMTP id q18mr14929345ejr.660.1643728109819; Tue, 01 Feb 2022 07:08:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643728109; cv=none; d=google.com; s=arc-20160816; b=SecslDRMYbnwR6tcxRWyJPIeFh5kW+ZTTDEOV12N5VoBsllUlGOAe+ZQE2N3pMBV2t 81BXpeeL/7/WzpPutB1mtYQl+h0ZmiHqHhFjvUpkooiojn0aQvHe0NTT/b95PaXjOdN6 lTFKJnIFmMZGjZXCf+RI8/e7SdkKO8c/YR9L5qdlguSHL5xR3Eq2Qq+jEO8F8FWxDe4B I6Yw/Fq1xbSYj2B7pxMgDAZBYYzc3DrxxNd2HgYyBnkcoBFrL9KEeQB4Dz2Gvr+fPHAt lMsYxT7vdSJmOSeaR+iuCnF6L7un/tn9h7eHOC+oT6TSc0l2e3OAbGwreCRMFmrmWnUu D6Mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature; bh=Nfmd/kAdxdoWmw7ILCi6KV9pxPaOEGnh8ZNTUcyAgsI=; b=Ip5NshJASZYXtJjwSgJLBq51OeGXL8hqbZTKm5ZX9pqmfQxV9zjfnT9OyUyguchL60 iMCPOEKKBkflhUK/LaEPnA1GD65IfdebVLEOJzU2MZegJ4eG+ugQJcGPZU7Ec3mLRSsT c1juF1kRwT5fPz298VNHW0eK5mCC8cAeTLUwmySwT//SrbnHr5w0YQf7S0OYUvL25nVY UhhiiRw+GSpRKN2tqcx13Da4Xv1kjJcVYRxHDkyuNKQ9IURpWVl+O5NV6louIuUVGl0t 82XGPv+05wZ11cC6ugtyRS2KABPheUT7F1APtlPmoYgkLBp7CSNtu2Z4UOCJ7t/kOc3w qMZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LrrSajmx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i22si11057842ejw.570.2022.02.01.07.08.01; Tue, 01 Feb 2022 07:08:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=LrrSajmx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S243726AbiA3VYv (ORCPT + 99 others); Sun, 30 Jan 2022 16:24:51 -0500 Received: from mga06.intel.com ([134.134.136.31]:52048 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356664AbiA3VWU (ORCPT ); Sun, 30 Jan 2022 16:22:20 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1643577740; x=1675113740; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=Swb/A+mwAZL7amzdZG31LHVm/8xpjESoIsbIiYe+fFo=; b=LrrSajmxvxfHBx2P0/AoXjkO3MGajkhEh3/7D9nYFuXSH+xjrArgaXmB awIA9qE31uIbvkVmeZfI41ifrjJY1Vf55br+sp0NpY19ZWRSiVVgVeFiV mSgHQIrz2UvdfpaladJcHuFDxbl8FQzg6YaCC1T0xKF1sUDQE4rmLhhIx 7Qd67KBsXQTs2e3QtJJCjErfNsqWw4I1HvjZ+Y7uPcx+2wyDw4OThHnfx h14PxFwIWK3rRkRataU7OZgZg+NvqdDOl8BIV+BVftAZPh/0vumkY7QTt rt3KjslQz3RoOhRj1yOHy0PaOOBvvQBKCtAr+bGJQkDZEfnl00BSBA77i Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10243"; a="308104951" X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="308104951" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:22:02 -0800 X-IronPort-AV: E=Sophos;i="5.88,329,1635231600"; d="scan'208";a="536856845" Received: from avmallar-mobl1.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.209.123.171]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jan 2022 13:22:01 -0800 From: Rick Edgecombe To: 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: rick.p.edgecombe@intel.com, Yu-cheng Yu Subject: [PATCH 21/35] mm/mprotect: Exclude shadow stack from preserve_write Date: Sun, 30 Jan 2022 13:18:24 -0800 Message-Id: <20220130211838.8382-22-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220130211838.8382-1-rick.p.edgecombe@intel.com> References: <20220130211838.8382-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yu-cheng Yu In change_pte_range(), when a PTE is changed for prot_numa, _PAGE_RW is preserved to avoid the additional write fault after the NUMA hinting fault. However, pte_write() now includes both normal writable and shadow stack (RW=0, Dirty=1) PTEs, but the latter does not have _PAGE_RW and has no need to preserve it. Exclude shadow stack from preserve_write test, and apply the same change to change_huge_pmd(). Signed-off-by: Yu-cheng Yu Reviewed-by: Kirill A. Shutemov Signed-off-by: Rick Edgecombe --- v25: - Move is_shadow_stack_mapping() to a separate line. v24: - Change arch_shadow_stack_mapping() to is_shadow_stack_mapping(). mm/huge_memory.c | 7 +++++++ mm/mprotect.c | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 1c7167e6f223..01375e39b52b 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1750,6 +1750,13 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, return 0; preserve_write = prot_numa && pmd_write(*pmd); + + /* + * Preserve only normal writable huge PMD, but not shadow + * stack (RW=0, Dirty=1). + */ + if (is_shadow_stack_mapping(vma->vm_flags)) + preserve_write = false; ret = 1; #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION diff --git a/mm/mprotect.c b/mm/mprotect.c index b0012c13a00e..faac710f0891 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -77,6 +77,13 @@ static unsigned long change_pte_range(struct vm_area_struct *vma, pmd_t *pmd, pte_t ptent; bool preserve_write = prot_numa && pte_write(oldpte); + /* + * Preserve only normal writable PTE, but not shadow + * stack (RW=0, Dirty=1). + */ + if (is_shadow_stack_mapping(vma->vm_flags)) + preserve_write = false; + /* * Avoid trapping faults against the zero or KSM * pages. See similar comment in change_huge_pmd. -- 2.17.1