From patchwork Wed Nov 2 09:12:47 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: 14135 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp3504214wru; Wed, 2 Nov 2022 02:15:07 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6GXE+BQudnsPsPOnI4cIYrd8wazKJSQfPLByv4J0mB8S69ILuZSxEpBogzAuBZtnsLMFf8 X-Received: by 2002:a17:90a:7c47:b0:212:ea80:8b02 with SMTP id e7-20020a17090a7c4700b00212ea808b02mr24512102pjl.60.1667380507146; Wed, 02 Nov 2022 02:15:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667380507; cv=none; d=google.com; s=arc-20160816; b=nUwZb8CzSXqpQS2hwe8V5ZwX4AHqGQAMjMtWiG4WUuYaU3wUU7ZbPlORY3ljp+DINm hvRxYLwjZXKgO2koAhz/YoScm2Kseu6rqfmMOKnXcOIXmGg1WvQxkvVGaNS866MUMELo VYFg8lzMmPTUOotw7dgXquQ0rU6MFLUG9FFlZb3GD53XThKyWAYZwb9gZ5gpbB7pYpcL jSS3PP4MUjgzISdDsyoD5P6ufLPd9ZYDXXHqxa8XfTEI399+feQPSabMHSzXp00SMsVl 9AJUa6E3sEEGUYoAl7xlB5fhqmoT3oip0ti9egOFUGcMx5Tl4kfTinSar6jgDOJn2ntU vDUg== 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=tHIjnJe16gue8Q322qjop+qto5RQegQc/YhsoeJNQZk=; b=FlNLBjLOVyaLCsPrKAscD1g6BOD9WQhkTvyl5tcnbAv1haTL5iuZD+4voBbqO+oi3f QctsLXqjojr0+Nezy7tmzTqz89kCPrNwEzF9k3l3ptZdnnxLj+x+EDwPK/AFXKAjIzIF dnqSzn1AIlAM1SMarLUpXhX3R2GHLkVGXSPF7srVHVga/TecPgNI2b95+LyAl6KDOSBM ShN9X2KmrCDuCmPq5VCZypILo+NgGGSGbLFSA4C3USGpOjN+PumjfkPxhH4IXAFSvUiy wWHBxY43nbS6BRyNpc8iT5bRT36jXKbqVnb9Q7YapJuOzjGmWstV3nG4/2dBXTK+Qu7f ziOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b="K/+nbRmM"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=t6dRcYm4; 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 s5-20020a170902ea0500b00186de874df8si17995523plg.442.2022.11.02.02.14.52; Wed, 02 Nov 2022 02:15:07 -0700 (PDT) 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="K/+nbRmM"; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=t6dRcYm4; 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 S231547AbiKBJOi (ORCPT + 99 others); Wed, 2 Nov 2022 05:14:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231214AbiKBJNN (ORCPT ); Wed, 2 Nov 2022 05:13:13 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DF86286CF; Wed, 2 Nov 2022 02:12:50 -0700 (PDT) Date: Wed, 02 Nov 2022 09:12:47 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1667380368; 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=tHIjnJe16gue8Q322qjop+qto5RQegQc/YhsoeJNQZk=; b=K/+nbRmMRJ/hi3/8hgsrsGcHenLBDwU/y99wDRZ4hF/2xwkFG+x5NqiKDicOccXxuoVdXf 6EoO0X2HRgoTpUQO9NBnNF6H5WR1Em1GijgGOeZ2bnlImLO/n/f95PJ6rPNomG5tOScFhS lMu9XCEgj38kXP70pDqaQ0+ztpTae2HNn14FFxEWyl+LAjlJNEepjI7QlN6xuRWipr1QdV Siwf//9n+DcH7j7tNKAbuUJ5on/IDa6Xz/MLHMPqzdQoLoBAQQfwpsvmKwWxrxSSEAu31X pnYgvF60MI+sdQ5G8y8DusVejL/e383Yn95kYhBHVo8UtocCF0RgsduIKQY44Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1667380368; 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=tHIjnJe16gue8Q322qjop+qto5RQegQc/YhsoeJNQZk=; b=t6dRcYm4kj8bGJTyIAjShfC4MZiEQLSUgxhs5h+gB5Yjnl3S6roa/lBlLCQqAF3VlDvwrr exAiveu5SPcKUrDQ== 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: Implement native set_memory_rox() Cc: Linus Torvalds , "Peter Zijlstra (Intel)" , x86@kernel.org, linux-kernel@vger.kernel.org MIME-Version: 1.0 Message-ID: <166738036738.7716.557888530898749563.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?1748375182481238922?= X-GMAIL-MSGID: =?utf-8?q?1748375182481238922?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: b38994948567e6d6b62947401c57f4ab2efe070c Gitweb: https://git.kernel.org/tip/b38994948567e6d6b62947401c57f4ab2efe070c Author: Peter Zijlstra AuthorDate: Sat, 29 Oct 2022 13:19:31 +02:00 Committer: Peter Zijlstra CommitterDate: Tue, 01 Nov 2022 13:43:59 +01:00 x86/mm: Implement native set_memory_rox() Provide a native implementation of set_memory_rox(), avoiding the double set_memory_ro();set_memory_x(); calls. Suggested-by: Linus Torvalds Signed-off-by: Peter Zijlstra (Intel) --- arch/x86/include/asm/set_memory.h | 3 +++ arch/x86/mm/pat/set_memory.c | 10 ++++++++++ include/linux/set_memory.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/arch/x86/include/asm/set_memory.h b/arch/x86/include/asm/set_memory.h index b45c4d2..a5e8964 100644 --- a/arch/x86/include/asm/set_memory.h +++ b/arch/x86/include/asm/set_memory.h @@ -6,6 +6,9 @@ #include #include +#define set_memory_rox set_memory_rox +int set_memory_rox(unsigned long addr, int numpages); + /* * The set_memory_* API can be used to change various attributes of a virtual * address range. The attributes include: diff --git a/arch/x86/mm/pat/set_memory.c b/arch/x86/mm/pat/set_memory.c index 97342c4..f275605 100644 --- a/arch/x86/mm/pat/set_memory.c +++ b/arch/x86/mm/pat/set_memory.c @@ -2025,6 +2025,16 @@ int set_memory_ro(unsigned long addr, int numpages) return change_page_attr_clear(&addr, numpages, __pgprot(_PAGE_RW), 0); } +int set_memory_rox(unsigned long addr, int numpages) +{ + pgprot_t clr = __pgprot(_PAGE_RW); + + if (__supported_pte_mask & _PAGE_NX) + clr.pgprot |= _PAGE_NX; + + return change_page_attr_clear(&addr, numpages, clr, 0); +} + int set_memory_rw(unsigned long addr, int numpages) { return change_page_attr_set(&addr, numpages, __pgprot(_PAGE_RW), 0); diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h index 023ebc6..95ac839 100644 --- a/include/linux/set_memory.h +++ b/include/linux/set_memory.h @@ -14,6 +14,7 @@ static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } #endif +#ifndef set_memory_rox static inline int set_memory_rox(unsigned long addr, int numpages) { int ret = set_memory_ro(addr, numpages); @@ -21,6 +22,7 @@ static inline int set_memory_rox(unsigned long addr, int numpages) return ret; return set_memory_x(addr, numpages); } +#endif #ifndef CONFIG_ARCH_HAS_SET_DIRECT_MAP static inline int set_direct_map_invalid_noflush(struct page *page)