From patchwork Fri Jun 10 23:35:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Weiny X-Patchwork-Id: 581346 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF2DFCCA47B for ; Fri, 10 Jun 2022 23:36:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350951AbiFJXgS (ORCPT ); Fri, 10 Jun 2022 19:36:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1350715AbiFJXgF (ORCPT ); Fri, 10 Jun 2022 19:36:05 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D80A7289A1C; Fri, 10 Jun 2022 16:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654904139; x=1686440139; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=qDvqVZ/A3fM/nZiMoOHgbdE/phpXdySZH6n5Muy9S6I=; b=l4ioGq080zDA2Ztv/LGQc+OC6/O79VljpHbjTmBkMBZKvvK9P81Y4VrX espfeU34hWlCbrtLp4vQlHtUjuq0RHjpZd6oo8WfCIWrEWVVPiZRATqOu Ey0JF1JCJ9X8aW+OYUnSoujIAvZl/YcFGAO7bfCHZuNhGgVRNnPpKIXcY P4gR51RVZO1cdtfa+vIKzy6oYPSxmI4vonO1EuZyC3sPv/yb668vnSPIx Ls1L3rqXwj2PMptq2Rjxago0Tbi3aKScUbdBu1IYBF+N3RYg3uMvPbWlV aG87CoYdfmegfjxjJViDWs10xI6ukG8cFpdLUcunaWimYwNunnxwq3tVX A==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="278579377" X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="278579377" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:38 -0700 X-IronPort-AV: E=Sophos;i="5.91,291,1647327600"; d="scan'208";a="828500280" Received: from pleung-mobl1.amr.corp.intel.com (HELO localhost) ([10.212.33.34]) by fmsmga006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 16:35:37 -0700 From: ira.weiny@intel.com To: linux-api@vger.kernel.org Cc: Ira Weiny , Dave Hansen , "Aneesh Kumar K . V" , Sohil Mehta , x86@kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org Subject: [RFC PATCH 3/6] testing/pkeys: Add additional test for pkey_alloc() Date: Fri, 10 Jun 2022 16:35:30 -0700 Message-Id: <20220610233533.3649584-4-ira.weiny@intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220610233533.3649584-1-ira.weiny@intel.com> References: <20220610233533.3649584-1-ira.weiny@intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org From: Ira Weiny When pkeys are not available on the hardware pkey_alloc() has specific behavior which was previously untested. Add test for this. Cc: Dave Hansen Cc: Aneesh Kumar K.V Signed-off-by: Ira Weiny --- tools/testing/selftests/vm/protection_keys.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 43e47de19c0d..4b733a75606f 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1554,6 +1554,16 @@ void test_implicit_mprotect_exec_only_memory(int *ptr, u16 pkey) do_not_expect_pkey_fault("plain read on recently PROT_EXEC area"); } +void test_pkey_alloc_on_unsupported_cpu(void) +{ + int test_pkey = sys_pkey_alloc(0, 0); + + dprintf1("pkey_alloc: %d (%d %s)\n", test_pkey, errno, + strerror(errno)); + pkey_assert(test_pkey < 0); + pkey_assert(errno == ENOSPC); +} + void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) { int size = PAGE_SIZE; @@ -1688,6 +1698,8 @@ int main(int argc, char *argv[]) printf("running PKEY tests for unsupported CPU/OS\n"); + test_pkey_alloc_on_unsupported_cpu(); + ptr = mmap(NULL, size, PROT_NONE, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); assert(ptr != (void *)-1); test_mprotect_pkey_on_unsupported_cpu(ptr, 1);