From patchwork Tue Nov 15 22:26:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 20616 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2971349wru; Tue, 15 Nov 2022 14:29:02 -0800 (PST) X-Google-Smtp-Source: AA0mqf4oKH4qrwZAbzdQ7UnMiv2wvkXAUhamPrKF/TslhPDYhRl8niLr4JArawEp6aGXWpujeeZ0 X-Received: by 2002:aa7:d4c7:0:b0:458:7489:34ea with SMTP id t7-20020aa7d4c7000000b00458748934eamr17614273edr.264.1668551342570; Tue, 15 Nov 2022 14:29:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668551342; cv=none; d=google.com; s=arc-20160816; b=HcN6k4rOI4o/K9uB/JALIXzIAO7ZFAjforX9Ct3oyyOr7c9dPu0AdNYqJK88jHHsEE OiSqlcJZuZm+DJ02ccqnu+GtkW7xOZZFbWiT7bHtG4h5xfLuEHEEjB66RlRXEl0Go7z3 BaEsxjvhuk0vT4vx7zrep3whFTLtiNs98vKPI4HyIg06N3MvAXiKGN3bp79zqI3TrTrk qVsG1BUau+NDC1gqq0kDv8P+5uwjHQc8pcHFgbufDiMyUhJ2wNsBEU1tmL+1I7CDo8Hj jbKvZ7MwYdnQd3JO92iP4XSJIsdwWN6/lrReRubxGlXBK7hWAijwTuJ4jmHlBeAa3bF4 lsvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:cc:subject:to:reply-to:sender:from :dkim-signature:dkim-signature:date; bh=pn5UtiqnRGWlXM480Esc6q28LEpVXsJC04ec2EQZjWU=; b=OHvmxzVm9451ABBWDEO76hJpn7T/KcKfHEpBURxMFd7PYRie7QtLrjZXX4W+y/4Ucr S2isw5IGM1QgoGiDw1nikZUcVotyobHgeu+m2bIOlUlnEBrjtd2XGvkpY5rCaHbuTb7M p9V4t4pSYQAfmYq9x+UtwRKpVbsQVlIvvUGO0GXwqK7G1UdKfN4TsLr2Lis00hMJYmJ+ nbpWogNUZLNcv9EJnytDxhUHGWmfXs7BMcuyS5uZ6wKPOB37Cc4hu5zctxmYkBJa3jy9 iT1yIECPPSPQDXAvQBwWJhk2LeUFIvDFDnK9BriXVGBICI8lK6e2qBBcTbwEp7h7zMyW pG0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dtbHKtn0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+tz4oZcJ; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h8-20020a50ed88000000b00461a8c8f155si11626287edr.161.2022.11.15.14.28.38; Tue, 15 Nov 2022 14:29:02 -0800 (PST) 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=@linutronix.de header.s=2020 header.b=dtbHKtn0; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=+tz4oZcJ; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238576AbiKOW1J (ORCPT + 99 others); Tue, 15 Nov 2022 17:27:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232203AbiKOW0m (ORCPT ); Tue, 15 Nov 2022 17:26:42 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48781317D2; Tue, 15 Nov 2022 14:26:29 -0800 (PST) Date: Tue, 15 Nov 2022 22:26:26 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1668551187; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pn5UtiqnRGWlXM480Esc6q28LEpVXsJC04ec2EQZjWU=; b=dtbHKtn0ZpWT4r3/2guQbR+S0Pi5H1Y7QsXcdviel3KIB8ztVDhG7Z7CG7tF/QmtPKjJBk SNZJbVrIlK9PLeo/7eWJw3jRRh653onuqOYNvmjuEdzNjh7WGa3X87RPDwlX4gwqyncGTd kbKhjErGHOLpmmydwS/7Ft2XWorr8ctVpjN4bZwmlI/NeU5zSplJc2DL2be9LTaxl5t5jS gZ3jLgDD/eaGd64XinGGcJbbPv80BPyZX/6x2x3Rv+Yv5KxIMV4IjJ5l0nhBvGsINS/FtJ PZqaFyRzxtbU29GxbGFODyh64VTFuc1+dvt3+Gel7/CEOrMeDrBHnlOdJkQMkw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1668551187; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pn5UtiqnRGWlXM480Esc6q28LEpVXsJC04ec2EQZjWU=; b=+tz4oZcJX9zq+tt9ZADPCtiyGR5gNQPdsORtpjPQ4naRXs3Con3PpsdHROYuTMPiMMDiut ceUowSkgJ7HurvDQ== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/mm] x86/mm: Inhibit _PAGE_NX changes from cpa_process_alias() Cc: kernel test robot , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <166855118670.4906.4131361261876319025.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749602892609273647?= X-GMAIL-MSGID: =?utf-8?q?1749602892609273647?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: 127960a05548ea699a95791669e8112552eb2452 Gitweb: https://git.kernel.org/tip/127960a05548ea699a95791669e8112552eb2452 Author: Peter Zijlstra AuthorDate: Thu, 10 Nov 2022 13:33:57 +01:00 Committer: Peter Zijlstra CommitterDate: Tue, 15 Nov 2022 22:29:58 +01:00 x86/mm: Inhibit _PAGE_NX changes from cpa_process_alias() There is a cludge in change_page_attr_set_clr() that inhibits propagating NX changes to the aliases (directmap and highmap) -- this is a cludge twofold: - it also inhibits the primary checks in __change_page_attr(); - it hard depends on single bit changes. The introduction of set_memory_rox() triggered this last issue for clearing both _PAGE_RW and _PAGE_NX. Explicitly ignore _PAGE_NX in cpa_process_alias() instead. Fixes: b38994948567 ("x86/mm: Implement native set_memory_rox()") Reported-by: kernel test robot Debugged-by: Dave Hansen Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20221110125544.594991716%40infradead.org --- arch/x86/mm/pat/set_memory.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 4943f6c..beef774 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -1669,6 +1669,12 @@ static int cpa_process_alias(struct cpa_data *cpa) alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY); alias_cpa.curpage = 0; + /* Directmap always has NX set, do not modify. */ + if (__supported_pte_mask & _PAGE_NX) { + alias_cpa.mask_clr.pgprot &= ~_PAGE_NX; + alias_cpa.mask_set.pgprot &= ~_PAGE_NX; + } + cpa->force_flush_all = 1; ret = __change_page_attr_set_clr(&alias_cpa, 0); @@ -1691,6 +1697,15 @@ static int cpa_process_alias(struct cpa_data *cpa) alias_cpa.flags &= ~(CPA_PAGES_ARRAY | CPA_ARRAY); alias_cpa.curpage = 0; + /* + * [_text, _brk_end) also covers data, do not modify NX except + * in cases where the highmap is the primary target. + */ + if (__supported_pte_mask & _PAGE_NX) { + alias_cpa.mask_clr.pgprot &= ~_PAGE_NX; + alias_cpa.mask_set.pgprot &= ~_PAGE_NX; + } + cpa->force_flush_all = 1; /* * The high mapping range is imprecise, so ignore the @@ -1709,6 +1724,12 @@ static int __change_page_attr_set_clr(struct cpa_data *cpa, int checkalias) unsigned long rempages = numpages; int ret = 0; + /* + * No changes, easy! + */ + if (!(pgprot_val(cpa->mask_set) | pgprot_val(cpa->mask_clr))) + return ret; + while (rempages) { /* * Store the remaining nr of pages for the large page @@ -1755,7 +1776,7 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages, struct page **pages) { struct cpa_data cpa; - int ret, cache, checkalias; + int ret, cache; memset(&cpa, 0, sizeof(cpa)); @@ -1805,10 +1826,7 @@ static int change_page_attr_set_clr(unsigned long *addr, int numpages, cpa.curpage = 0; cpa.force_split = force_split; - /* No alias checking for _NX bit modifications */ - checkalias = (pgprot_val(mask_set) | pgprot_val(mask_clr)) != _PAGE_NX; - - ret = __change_page_attr_set_clr(&cpa, checkalias); + ret = __change_page_attr_set_clr(&cpa, 1); /* * Check whether we really changed something: