From patchwork Sat Dec 17 18:55:34 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: 34247 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp1636401wrn; Sat, 17 Dec 2022 10:58:42 -0800 (PST) X-Google-Smtp-Source: AMrXdXvPv+oDjhm8ZdUV1apxmy80ew2QUO0oWy4J9DeLd4Ci8JvHqjnaOZGqRmD4HOmWC5N38MTQ X-Received: by 2002:aa7:dc04:0:b0:472:3008:bcfc with SMTP id b4-20020aa7dc04000000b004723008bcfcmr13891909edu.15.1671303521924; Sat, 17 Dec 2022 10:58:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671303521; cv=none; d=google.com; s=arc-20160816; b=KAhMwu7yiQGi/5f392vAmYdvcePlGuMsRvZVSTBgrHVu5HoXp9NOUS+IwZGGpVkp/P JfkMdBdAnrmpcIKaxTpgQpnMt6UO66IVEy2OYJlfFyi4gHUDS4fgNc62WeZbnUP9x8ai KL/CAT/Cd7UTiRJ6mZsTRuVhkoHiAWeQfpxh0YmGBMX49z191NPKoD/QGAY8aRMI+ybf z31YP/9xK1pR4CzQiiqziezZsmTih6Z0LwJTKGTet7YoGAPV/ry4wDoaHzLMH2b0k2RD WXuBZiY3ZtJZGBJg6awLzbxKZKE5zoFrFa0o93B1XD2IdxeS2pV2MJTg1swiC5gyX3Wg Esag== 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=NgFTl5Yz2InkjiWBTu9ICyXDDvM0swdcxAoy/RoyX0I=; b=muFlzCa6JdNOv+pw3QsAoWyS+6NC/6G2FT5m5Iorp51gKRE/Dxq9lTO2W7mrmEwqKT 2LSC+5FZh3HlfNjLa3YvVKeE2Uxhv6RV4CajJ974fDS/pcsVZ9CgO3YaFrDWi8fb7fA7 rGXCCxgojGgM7XFUryx7CJ70LapHjKD9TIAVynElXbGR5SmNG0ta/WBteCWiGfApa/fA hdyv5F8KmdGrJhOZPRZqkCaoTjwazZc0I8f9awo3obD7pe/fhlTUh09J9nKKzkpxHcPf kYk+z8y0Yw+7yRoUnWLTZSNaVxreZUc62dCy9zdoA4taWjpyjspsi/LyhlvN6av3Fe92 XfbA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=dq00EcVr; dkim=neutral (no key) header.i=@linutronix.de; 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 o20-20020a170906975400b0078d4cf8de04si5961927ejy.380.2022.12.17.10.58.19; Sat, 17 Dec 2022 10:58:41 -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=dq00EcVr; dkim=neutral (no key) header.i=@linutronix.de; 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 S230284AbiLQS5e (ORCPT + 99 others); Sat, 17 Dec 2022 13:57:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230081AbiLQSzk (ORCPT ); Sat, 17 Dec 2022 13:55:40 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 281F6381; Sat, 17 Dec 2022 10:55:38 -0800 (PST) Date: Sat, 17 Dec 2022 18:55:34 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1671303334; 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=NgFTl5Yz2InkjiWBTu9ICyXDDvM0swdcxAoy/RoyX0I=; b=dq00EcVranZdNL4sBSTKDs9Pof9ihke4N401paG64/MuGxIHFsgzhq4IILUKidxyaGdUAt iyv5PRCSMXKbgL0IZQ/gmIBbzLgiWPHFLcZi+x8lXTDYaNj10B1oyJlkiyfk0ZBQ5Sc+wQ u8jD9K+pdmpYk5/V41AmkTLnajEMvAIbgvzGv6YJBBwWh0acvRgT2MkCeHPjWOfW6/inNd 0CXeJXdR3KlLonMdLyEUn0AaeyYUXb6CUJ8eK9zO0Jq7++Ks1kzNj9U6V6lWqbscA36bMC HCvPzv19+G7Mb4ws1o+pujmeCp77jljeMmb4y2hskkvgBW8Vw5XJf25NFIkZSA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1671303334; 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=NgFTl5Yz2InkjiWBTu9ICyXDDvM0swdcxAoy/RoyX0I=; b=1NBtNEyu1TeRG/HwVLMxxVzCtBntj/OGJJnfo/Gfxl4NsftACuPrtM+6V9LW1VYS0uecGn zIqsT/a+oUHsKQAw== 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: <167130333441.4906.5813046131374369932.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?1752488762083825886?= X-GMAIL-MSGID: =?utf-8?q?1752488762083825886?= The following commit has been merged into the x86/mm branch of tip: Commit-ID: 60463628c9e0a8060ac6bef0457b0505c7532c7c Gitweb: https://git.kernel.org/tip/60463628c9e0a8060ac6bef0457b0505c7532c7c Author: Peter Zijlstra AuthorDate: Sat, 29 Oct 2022 13:19:31 +02:00 Committer: Dave Hansen CommitterDate: Thu, 15 Dec 2022 10:37:27 -08: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)