Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1544180ybh; Tue, 14 Jul 2020 00:08:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJytfYEreix6npKKImUqkNXy4KBbwzduCO8BkLV5tZaUGxRrfJiRNV4yoK59z7t44iuZ1K1h X-Received: by 2002:a17:907:7245:: with SMTP id ds5mr3172991ejc.1.1594710513823; Tue, 14 Jul 2020 00:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594710513; cv=none; d=google.com; s=arc-20160816; b=NfOgWV/oEFmdeIBg9JwkmToSgBAv2Z+OrpysdjJQOF+uJFnBlin6EWTlAmgMokaYDZ cC6qBwhbwvZAfkm2nu88PVDiKkpSyysiReXhkJqF98gjod1Bkc/lDxfKHbICpr1S1/qy lSakEEyUwcuTGhcg0tfr/Uu6Xq6yqwiyXRue1/f6L42/mlTbWDsnaCZedMxcF4S4STaS uyM2EXU6LxzUu2tzRyX5ASBzkYr6sMWT29TvYywTWvFIQGx0lkLEe2RGeZjr2867+E5C W0ijLZzVAJ9tmaxtLD2VGVRDUcgGjSCeN20/4sGqw/cP9VXB5Jl0DKoUvLOnSB19Pt9H FCzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=9yUeRbdysWB5Bdd4r960KL6HLh0/HkYXP/Sn8Q8478g=; b=X7MAXIk9ZzM6dWgpziBua/fo0wUdah0iScryVl1x+rhT6a0xumsZv7s4VFJ5gV+kFT ADMOwdkZo2xdKhJ7Xye9kdkZxvuSvkdYqX/p0tUDmC1/qsp3IwIKTZPqXd6gxZq7wy3v bABayYTR37I4tN9EHlMZx59ypBEd5214vpntTuBcUv4nPTw0iuwPL4IxclCMUi0ARxJs 4r6qcuXruhbr7F3zofqpcju5d+9X0UkNS1rMGI1cs+6CyOv3F1JQOp11j6QvPP/ZtFHb KTVDVcr2ofvnLainkqG2rLnKDxySseL2lzkkwLagFwyeQT8/G7DPd0VPF4ZUQDTB6khJ IPBw== 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 c3si10927110edy.147.2020.07.14.00.08.11; Tue, 14 Jul 2020 00:08: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 S1727863AbgGNHFd (ORCPT + 99 others); Tue, 14 Jul 2020 03:05:33 -0400 Received: from mga11.intel.com ([192.55.52.93]:63464 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726890AbgGNHEP (ORCPT ); Tue, 14 Jul 2020 03:04:15 -0400 IronPort-SDR: tbX199lH6+gxoeI89r9ex3VBW/twRf3oWwEnCQqLdU4FfTnUFU66rAbnrVblQlvOwVjbghLN1h JQu4qXWOtYJQ== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="146839879" X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="146839879" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 00:04:11 -0700 IronPort-SDR: 2S/nvFjzQ392JiaSqjcp8ScDg96hb1apbpi4JcpWqJ5/phFArv7EiT3mk7FEux00XHBnw/HaLS IAyf6X3DxdnQ== X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="324463867" Received: from iweiny-desk2.sc.intel.com (HELO localhost) ([10.3.52.147]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jul 2020 00:04:11 -0700 From: ira.weiny@intel.com To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , Peter Zijlstra Cc: Fenghua Yu , x86@kernel.org, Dave Hansen , Dan Williams , Vishal Verma , Ira Weiny , Andrew Morton , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-nvdimm@lists.01.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH 06/15] x86/pks: Add a debugfs file for allocated PKS keys Date: Tue, 14 Jul 2020 00:02:11 -0700 Message-Id: <20200714070220.3500839-7-ira.weiny@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200714070220.3500839-1-ira.weiny@intel.com> References: <20200714070220.3500839-1-ira.weiny@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Fenghua Yu The sysadmin may need to know which PKS keys are currently being used. Add a debugfs file to show the allocated PKS keys and their names. Signed-off-by: Fenghua Yu --- arch/x86/mm/pkeys.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/arch/x86/mm/pkeys.c b/arch/x86/mm/pkeys.c index 16f735c12fcd..e565fadd74d7 100644 --- a/arch/x86/mm/pkeys.c +++ b/arch/x86/mm/pkeys.c @@ -328,3 +328,43 @@ void pks_key_free(int pkey) mutex_unlock(&pks_lock); } EXPORT_SYMBOL_GPL(pks_key_free); + +static int pks_keys_allocated_show(struct seq_file *m, void *p) +{ + int i; + + mutex_lock(&pks_lock); + for (i = PKS_KERN_DEFAULT_KEY; i < PKS_NUM_KEYS; i++) { + /* It is ok for pks_key_users[i] to be NULL */ + if (test_bit(i, &pks_key_allocation_map)) + seq_printf(m, "%d: %s\n", i, pks_key_users[i]); + } + mutex_unlock(&pks_lock); + + return 0; +} + +static int pks_keys_allocated_open(struct inode *inode, struct file *file) +{ + return single_open(file, pks_keys_allocated_show, NULL); +} + +static const struct file_operations pks_keys_allocated_fops = { + .open = pks_keys_allocated_open, + .read = seq_read, + .llseek = seq_lseek, + .release = single_release, +}; + +static int __init pks_keys_initcall(void) +{ + if (cpu_feature_enabled(X86_FEATURE_PKS)) { + /* Create a debugfs file to show allocated PKS keys. */ + debugfs_create_file("pks_keys_allocated", 0400, + arch_debugfs_dir, NULL, + &pks_keys_allocated_fops); + } + + return 0; +} +late_initcall(pks_keys_initcall); -- 2.25.1