Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1002446pxj; Thu, 27 May 2021 17:32:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyRKz/xYbOP4Z09NdNEVE4umY6XVzgtCw4UCqAC5aKwZB7n0j2qDCcrryV1ze1tMDngH6F7 X-Received: by 2002:a6b:3b92:: with SMTP id i140mr4995872ioa.23.1622161953307; Thu, 27 May 2021 17:32:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622161953; cv=none; d=google.com; s=arc-20160816; b=IrPHJDMXa3JJ0cGbYm5IdeO0R5jBrnnCjLU2BE05/iWtN2cR5T9Es8yPtUjqSPxPun 0j3lfgStqovcS9F7fr0ULajKLUvJWFNW0weHzZzQ3O6sQgyuXqEhnT9imxxBACkts4us YjaEcdQsVq27HYe30UzDEI7DOzafu5ojlPdeQqmCL7oCYdC+Crtw2MSCrKMLf3Eg6rlc dqfnog8499tabUp+z3YaKsKAJ6o3OU9XHJYULvLjA3/fobhxAgYqe52qqwQMwKYLj3NW VuQRC05u3qil8yK8nEmqcnLx7mE6W4lIBRhQzLrh8Nn2zzWdoUFOXQ7YnHzq11vM3dR/ JV7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:in-reply-to:references:date:from:cc :to:subject:ironport-sdr:ironport-sdr; bh=wLCHgewv9IE6NTW3ZiXnfxjPyKQxy5w3vu2bBcJ3An0=; b=NFJijoqkyH9VTHvgE+nxHCN8nxLFRIc7lI4/kfy1oUxtHWHyHJo5pvGLR9gFVqOqb+ 7Fyhd+uQDqK0eC9WGmkYnEwx7c6s4TC18hjpDa0jia5u+vsilxbp7jkUBWLzwyRwDTqd xfwxOaO4sCxI62Mng8nV0t2lHjcHV90KcZmWA/mm2bm5HGT7UhPVDMaRW8af9Dgr7ONO Ncc9r4lGRlxs2PTEm+EmukMoG+qRhp8viE1JB/nSTstcKsZrS2jHzOBvo8ST6Vbh5vH+ TTMAxG/4/C1VJh0n9a1jwBA9CvkZx2Fd5yqDedrnPYL95WW4CY4ZwFWMSXIqPeW1Pndu hmjw== 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 r9si4210236iol.40.2021.05.27.17.32.19; Thu, 27 May 2021 17:32:33 -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 S235452AbhE0X7l (ORCPT + 99 others); Thu, 27 May 2021 19:59:41 -0400 Received: from mga06.intel.com ([134.134.136.31]:62232 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236706AbhE0X7M (ORCPT ); Thu, 27 May 2021 19:59:12 -0400 IronPort-SDR: So1ghIB51NVU+2Yoh/DLuRtMcw89221B7nY6NCm+sNCoFbZTsg37F9QfrpszTAq/iOS8/vMldQ Z7v7/HDqjycg== X-IronPort-AV: E=McAfee;i="6200,9189,9997"; a="264056306" X-IronPort-AV: E=Sophos;i="5.83,228,1616482800"; d="scan'208";a="264056306" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 May 2021 16:57:37 -0700 IronPort-SDR: 9ZFlg3sGbjSQxnOyaaTDmNRe3esrK6QKVLZjgaZeDojwcFOC1gLIryltHoXaSBDLcmDkBnsP99 M1Wcq2ajCfsA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,228,1616482800"; d="scan'208";a="615568004" Received: from viggo.jf.intel.com (HELO localhost.localdomain) ([10.54.77.144]) by orsmga005.jf.intel.com with ESMTP; 27 May 2021 16:57:37 -0700 Subject: [PATCH 3/5] x86/pkeys: skip 'init_pkru' debugfs file creation when pkeys not supported To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Dave Hansen , tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, x86@kernel.org, luto@kernel.org, shuah@kernel.org, babu.moger@amd.com, dave.kleikamp@oracle.com, linuxram@us.ibm.com, bauerman@linux.ibm.com, bigeasy@linutronix.de From: Dave Hansen Date: Thu, 27 May 2021 16:51:16 -0700 References: <20210527235109.B2A9F45F@viggo.jf.intel.com> In-Reply-To: <20210527235109.B2A9F45F@viggo.jf.intel.com> Message-Id: <20210527235116.E5A35872@viggo.jf.intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Dave Hansen The PKRU hardware is permissive by default: all reads and writes are allowed. The in-kernel policy is restrictive by default: deny all unnecessary access until explicitly requested. That policy can be modified with a debugfs file: "x86/init_pkru". This file is created unconditionally, regardless of PKRU support in the hardware, which is a little silly. Avoid creating the file when pkeys are not available. This also removes the need to check for pkey support at runtime, which would be required once the new pkey modification infrastructure is put in place later in this series. Signed-off-by: Dave Hansen Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: x86@kernel.org Cc: Andy Lutomirski Cc: Shuah Khan Cc: Babu Moger Cc: Dave Kleikamp Cc: Ram Pai Cc: Thiago Jung Bauermann Cc: Sebastian Andrzej Siewior --- b/arch/x86/mm/pkeys.c | 4 ++++ 1 file changed, 4 insertions(+) diff -puN arch/x86/mm/pkeys.c~x86-pkeys-skip-debugfs-file arch/x86/mm/pkeys.c --- a/arch/x86/mm/pkeys.c~x86-pkeys-skip-debugfs-file 2021-05-27 16:40:25.847705465 -0700 +++ b/arch/x86/mm/pkeys.c 2021-05-27 16:40:25.852705465 -0700 @@ -193,6 +193,10 @@ static const struct file_operations fops static int __init create_init_pkru_value(void) { + /* Do not expose the file if pkeys are not supported. */ + if (!cpu_feature_enabled(X86_FEATURE_OSPKE)) + return 0; + debugfs_create_file("init_pkru", S_IRUSR | S_IWUSR, arch_debugfs_dir, NULL, &fops_init_pkru); return 0; _