From patchwork Tue Jul 17 13:49:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10529505 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id AC1226020A for ; Tue, 17 Jul 2018 13:50:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92F9128D8A for ; Tue, 17 Jul 2018 13:50:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 86D0E29221; Tue, 17 Jul 2018 13:50:47 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F8AE29087 for ; Tue, 17 Jul 2018 13:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731589AbeGQOXc (ORCPT ); Tue, 17 Jul 2018 10:23:32 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:40234 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731748AbeGQOXc (ORCPT ); Tue, 17 Jul 2018 10:23:32 -0400 Received: by mail-qt0-f195.google.com with SMTP id h4-v6so885679qtj.7; Tue, 17 Jul 2018 06:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=tpjjVJNvXu8hAFs53oogeqRK2jibwNpfYB6tEGPZTag=; b=GSDmSzI3LSUsihkTMGJdw7BoivmYZVl+6EH4mZudN4fhbxiXVXzuXnaMdVy9l5FTqn 8ByM0Eu035saI/yyEUa7g8Z68XeAom9N7PPB635RnnJNADjPzO/jZDLAcARPWPiHLiKt pIm3xhVlbpnITsQRlSAcrg51Jo4LOgXfgSiZ61T0Bwzneu3KMpoTkSaFjQu6tF93XJQx KiGqCvDis/UsZ/i0IjYaDL1KuvdCmLpzTOOCExhKCJKsII/SUktH8SOlvzABQCt6VGRR FHDxKKkDDtQbI5BLHGiZd5dkid0v7ODvx5Q2futDLg4J/ohPixMZxGCvmpaaSo5t6ucM xqzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=tpjjVJNvXu8hAFs53oogeqRK2jibwNpfYB6tEGPZTag=; b=ctsnmTT8MypGf/g7OPPtFWFjXuO/9ZBabnODq7NpjC0wZjddR9rMT22qADTxrt5eXg 7xwL5N9Db5zwrHfk6zqTCQf/ujSNeFOyKH2022asbYbKjxgTMhzsATWoP8Xd/H1iS1Wv fqAD3Bf9t+JU3ko3peVijuIlFTc8dUHSa5mWKsj66lWmnqD8KLSVlKyoC/L7bG1mY8FQ jMUHjoeCUhG+qmjWeQbpp1TXRLuu+BxVKpIyQq0ahbrmR0Mx9lnmUVNlxtUEn12fuBio q+HiPj6eJq98HKO+43UGpSSaW7BM4MdHzS31CX1A8bdDtwkPJd/RDjKum7jz5yfxtZTg M/Ng== X-Gm-Message-State: AOUpUlGuNChW2IYIKm5q8WbmUTmrN7KjbL1nKktjXyWcbgWVwlsZYAHg 4nv0BQdMYufRdaokPdZFvU8= X-Google-Smtp-Source: AAOMgpc8qQlwBwBpBWP18wyX1W+sFWZ3V99TJpmYfW+jklKpdtk6MJisWsRHBo0wZVC+BYt/Pq8leA== X-Received: by 2002:ac8:f24:: with SMTP id e33-v6mr1626546qtk.301.1531835445428; Tue, 17 Jul 2018 06:50:45 -0700 (PDT) Received: from localhost.localdomain (50-39-100-161.bvtn.or.frontiernet.net. [50.39.100.161]) by smtp.gmail.com with ESMTPSA id s83-v6sm640937qki.20.2018.07.17.06.50.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jul 2018 06:50:45 -0700 (PDT) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Cc: mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, linux-mm@kvack.org, x86@kernel.org, linux-arch@vger.kernel.org, mingo@redhat.com, dave.hansen@intel.com, mhocko@kernel.org, bauerman@linux.vnet.ibm.com, linuxram@us.ibm.com, fweimer@redhat.com, msuchanek@suse.de, aneesh.kumar@linux.vnet.ibm.com Subject: [PATCH v14 20/22] selftests/vm: testcases must restore pkey-permissions Date: Tue, 17 Jul 2018 06:49:23 -0700 Message-Id: <1531835365-32387-21-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> References: <1531835365-32387-1-git-send-email-linuxram@us.ibm.com> Sender: linux-kselftest-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Generally the signal handler restores the state of the pkey register before returning. However there are times when the read/write operation can legitamely fail without invoking the signal handler. Eg: A sys_read() operaton to a write-protected page should be disallowed. In such a case the state of the pkey register is not restored to its original state. Test cases may not remember to restoring the key register state. During cleanup generically restore the key permissions. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai --- tools/testing/selftests/vm/protection_keys.c | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 8a6afdd..ea3cf04 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1476,8 +1476,13 @@ void run_tests_once(void) pkey_tests[test_nr](ptr, pkey); dprintf1("freeing test memory: %p\n", ptr); free_pkey_malloc(ptr); + + /* restore the permission on the key after use */ + pkey_access_allow(pkey); + pkey_write_allow(pkey); sys_pkey_free(pkey); + dprintf1("pkey_faults: %d\n", pkey_faults); dprintf1("orig_pkey_faults: %d\n", orig_pkey_faults);