Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp4030019pxb; Mon, 30 Aug 2021 17:01:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzFE17IHgid/xBn3/yJLmgIjBEVO+NA2Sr3Nmyl4Re/hEx7XknJLudxaPThXY9RaCIr+Edo X-Received: by 2002:a05:6602:200f:: with SMTP id y15mr19661062iod.64.1630368109541; Mon, 30 Aug 2021 17:01:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630368109; cv=none; d=google.com; s=arc-20160816; b=t4utacfA5wyFMwlL/0VxeccE8sMzoQXMTimR1abmkOWxjq2yffRg2Y6OGLmRJC8/p9 jCgjd+jJtGh6lqWNAbrSk0MC4iuGWh1XFIxJ3iD4F9pk3ytqXd2AYv8e8/FbJ+1DiVE7 wgtebSjwW+sOzIx8GCOysfLgVEHCb8lpNWYt5pxcIFU4Nf01EGdKOHhe+R9dFaDl9KX+ KgO8yAC3UuAcCXhN9nsss66tooi8qn9ua5/D0ebwFbpZ4gBIfwju7BMG9Q+f/oBmSF85 aHb/xz+/9oy7f6qUDGcQOpYWEuHDF4gr70Xxtk3BuifHDmlN9gry51DEj2fQEhIdwSeK U2Mg== 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; bh=Crp7IXnUj9gFNMDdColXbw3jP3HVHZQ+G1nWdNXrOdk=; b=gnNJqjVtofkq/V+DYBvxzv6oi6Is3TbQTiBPGeQE4VrI80DDeoKpzNsBbitv839BGB gDV4Hnjixdj97hRJYMGbGz777ngsV9BZpDIylbTMEl7lEpDpIR5nX1fGmffzXQnB6Oz1 Rj4uCn05j/aVKJNMQoB6Whg14WCcK1A7peTiEt8+0i42TjfuM/C02kULObY/xvx+0WuT TU2nueHCGBdRxpB49H6sR8y6BuWYQ6XGpsGeeP/mSHTDwG9fAfEdWJ1wseeVG6KcsIXV vcbuWuFrxFpom+rZwdbFH52OMURdZxYQO3ztUxQ1T0duiOXpaUh3EfFD8PiRsCfIFIaC Rezg== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 d185si584316jab.17.2021.08.30.17.01.38; Mon, 30 Aug 2021 17:01:49 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239318AbhHaABn (ORCPT + 99 others); Mon, 30 Aug 2021 20:01:43 -0400 Received: from mga09.intel.com ([134.134.136.24]:50163 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239229AbhHaABB (ORCPT ); Mon, 30 Aug 2021 20:01:01 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10092"; a="218381540" X-IronPort-AV: E=Sophos;i="5.84,364,1620716400"; d="scan'208";a="218381540" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2021 17:00:06 -0700 X-IronPort-AV: E=Sophos;i="5.84,364,1620716400"; d="scan'208";a="530712959" Received: from ajinkyak-mobl2.amr.corp.intel.com (HELO rpedgeco-desk.amr.corp.intel.com) ([10.212.240.95]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Aug 2021 17:00:05 -0700 From: Rick Edgecombe To: dave.hansen@intel.com, luto@kernel.org, peterz@infradead.org, x86@kernel.org, akpm@linux-foundation.org, keescook@chromium.org, shakeelb@google.com, vbabka@suse.cz, rppt@kernel.org Cc: Rick Edgecombe , linux-mm@kvack.org, linux-hardening@vger.kernel.org, kernel-hardening@lists.openwall.com, ira.weiny@intel.com, dan.j.williams@intel.com, linux-kernel@vger.kernel.org Subject: [RFC PATCH v2 13/19] mm/debug_vm_page_table: Use setters instead of WRITE_ONCE Date: Mon, 30 Aug 2021 16:59:21 -0700 Message-Id: <20210830235927.6443-14-rick.p.edgecombe@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210830235927.6443-1-rick.p.edgecombe@intel.com> References: <20210830235927.6443-1-rick.p.edgecombe@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Currently debug_vm_page_table uses some raw WRITE_ONCE invocations to write to page tables, which PKS tables is designed to prevent. So use the set_p**() helpers instead of WRITE_ONCE for x86, so debug_vm_page_table will work with PKS tables enabled. Signed-off-by: Rick Edgecombe --- mm/debug_vm_pgtable.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/mm/debug_vm_pgtable.c b/mm/debug_vm_pgtable.c index 1c922691aa61..a0b8859ecf04 100644 --- a/mm/debug_vm_pgtable.c +++ b/mm/debug_vm_pgtable.c @@ -411,11 +411,17 @@ static void __init pmd_huge_tests(pmd_t *pmdp, unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PMD huge\n"); + +#ifdef CONFIG_X86 + /* Use setter so that protections can be toggled if needed */ + set_pmd(pmdp, __pmd(0)); +#else + WRITE_ONCE(*pmdp, __pmd(0)); +#endif /* * X86 defined pmd_set_huge() verifies that the given * PMD is not a populated non-leaf entry. */ - WRITE_ONCE(*pmdp, __pmd(0)); WARN_ON(!pmd_set_huge(pmdp, __pfn_to_phys(pfn), prot)); WARN_ON(!pmd_clear_huge(pmdp)); pmd = READ_ONCE(*pmdp); @@ -430,11 +436,16 @@ static void __init pud_huge_tests(pud_t *pudp, unsigned long pfn, pgprot_t prot) return; pr_debug("Validating PUD huge\n"); +#ifdef CONFIG_X86 + /* Use setter so that protections can be toggled if needed */ + set_pud(pudp, __pud(0)); +#else + WRITE_ONCE(*pudp, __pud(0)); +#endif /* * X86 defined pud_set_huge() verifies that the given * PUD is not a populated non-leaf entry. */ - WRITE_ONCE(*pudp, __pud(0)); WARN_ON(!pud_set_huge(pudp, __pfn_to_phys(pfn), prot)); WARN_ON(!pud_clear_huge(pudp)); pud = READ_ONCE(*pudp); @@ -473,7 +484,12 @@ static void __init pud_clear_tests(struct mm_struct *mm, pud_t *pudp) pr_debug("Validating PUD clear\n"); pud = __pud(pud_val(pud) | RANDOM_ORVALUE); +#ifdef CONFIG_X86 + /* Use setter so that protections can be toggled if needed */ + set_pud(pudp, pud); +#else WRITE_ONCE(*pudp, pud); +#endif pud_clear(pudp); pud = READ_ONCE(*pudp); WARN_ON(!pud_none(pud)); @@ -514,7 +530,12 @@ static void __init p4d_clear_tests(struct mm_struct *mm, p4d_t *p4dp) pr_debug("Validating P4D clear\n"); p4d = __p4d(p4d_val(p4d) | RANDOM_ORVALUE); +#ifdef CONFIG_X86 + /* Use setter so that protections can be toggled if needed */ + set_p4d(p4dp, p4d); +#else WRITE_ONCE(*p4dp, p4d); +#endif p4d_clear(p4dp); p4d = READ_ONCE(*p4dp); WARN_ON(!p4d_none(p4d)); @@ -549,7 +570,12 @@ static void __init pgd_clear_tests(struct mm_struct *mm, pgd_t *pgdp) pr_debug("Validating PGD clear\n"); pgd = __pgd(pgd_val(pgd) | RANDOM_ORVALUE); +#ifdef CONFIG_X86 + /* Use setter so that protections can be toggled if needed */ + set_pgd(pgdp, pgd); +#else WRITE_ONCE(*pgdp, pgd); +#endif pgd_clear(pgdp); pgd = READ_ONCE(*pgdp); WARN_ON(!pgd_none(pgd)); @@ -610,8 +636,12 @@ static void __init pmd_clear_tests(struct mm_struct *mm, pmd_t *pmdp) pr_debug("Validating PMD clear\n"); pmd = __pmd(pmd_val(pmd) | RANDOM_ORVALUE); - WRITE_ONCE(*pmdp, pmd); +#ifdef CONFIG_X86 + /* Use setter so that protections can be toggled if needed */ pmd_clear(pmdp); +#else + WRITE_ONCE(*pmdp, pmd); +#endif pmd = READ_ONCE(*pmdp); WARN_ON(!pmd_none(pmd)); } -- 2.17.1