From patchwork Thu Jun 14 00:45:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 10463117 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 B2B14600D0 for ; Thu, 14 Jun 2018 00:48:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0C1728988 for ; Thu, 14 Jun 2018 00:48:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 954AA28BA8; Thu, 14 Jun 2018 00:48:06 +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=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36C3A28988 for ; Thu, 14 Jun 2018 00:48:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BCB5A6B028A; Wed, 13 Jun 2018 20:47:29 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id B7CE86B028C; Wed, 13 Jun 2018 20:47:29 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9805C6B028D; Wed, 13 Jun 2018 20:47:29 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt0-f198.google.com (mail-qt0-f198.google.com [209.85.216.198]) by kanga.kvack.org (Postfix) with ESMTP id 6B9746B028A for ; Wed, 13 Jun 2018 20:47:29 -0400 (EDT) Received: by mail-qt0-f198.google.com with SMTP id a10-v6so3373490qtp.2 for ; Wed, 13 Jun 2018 17:47:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:sender:from:to:cc:subject:date :message-id:in-reply-to:references; bh=6oR8SX/Ju15dFyQkrGmkBtdzRaqiBq4O7cLvGw4B2i4=; b=IMn3FKaOzYRarXWV8nB+kSjHR4umTSY0xlK5mE5py5ZG56PZo5WgAth1ssud9e+O8d C645b/ICgsWvT6nIoru+iXjCFlloc5wtc+LV+Dg9+iORyen1QevPZeZwTos9wOZZTGba vikqurxgHKbb/sk35sqcbnprUSPHTqNrIhFjYd3i4Rv0khRGOSaWPEGwTZU4lNhbib2o 9WV1eQeXxGFjgvJgUtd2vA7jasvz/CvmUBRIQ5fzzUhDarAHMRnqz1Kt2X/riq3CZQyW h+6psGz7o217b1EnMh8MwPtzKdIODd6qu4zn0JqQ/+WNkNakSTHXBCZcjm8JE6dP6tvg M09w== X-Gm-Message-State: APt69E2vcGy9d/G17/QbonsSM/6snPPLQ2IDPUsUP5Fgvfrz+T6OUrwo +szmGvzLEh7jXRJTsfIhAyhga4ElSaPDRizAEwRmUH+0Garn19RGIAnjSxvYGvZ91+2fPestp1k qK2bX9y6tWfvldlcQ9hUrF7vAnHEHOuFGGT+xE3z7ZOfvMmqn27IxjtK/7w2ch5u81T9lXPK64Q O+GHR11hirdHIYGvwtBUqoYvZM9x0gISq+EYCXc/r8jqjy0HCkAwKJlw+2+9Rzkjm4ypPBZ24R4 UF7w4fKFR4aerntnE8qiFuI3XxQaGu9vpne5YUY5VOQkV4zX0rn7mUs7pR+nY/GvkGoV5ju5vxZ huc/uti9VqEBe5OXkw6FL7MuN7kw5WgOOfc+vhgkWOAxuigl9gFIVgMOrEhIDLl9M7mbeB9JhA= = X-Received: by 2002:ac8:2e1c:: with SMTP id r28-v6mr390827qta.156.1528937249235; Wed, 13 Jun 2018 17:47:29 -0700 (PDT) X-Received: by 2002:ac8:2e1c:: with SMTP id r28-v6mr390801qta.156.1528937248547; Wed, 13 Jun 2018 17:47:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528937248; cv=none; d=google.com; s=arc-20160816; b=qv7dCQUlZpbBayBGqq9QA2HBo4lnBDlZBrhd6dLZirDoagJMre6XS8XVeayPDv5Esw ywcJVBH1/XBWKeYkNgD8R3uHjia5KAKnVtb6v/+8MizOCeMV9wpaSsXpbKwE+837lM9S BZPWxw2TiOXpaW/EgL6GrDnSm753Fsgq+qhsByaMVwhysd+ebP4Y3wR0TBRs1MzRr3gj 1Gi2qjFcEwEIeA5G14O8uDi40xgMFllffNrXdwPOpiGKQfbUlLJNOCyMtm6FAyw3Zpyy p8eLj7bYvc+KIGukhlFkLrAD2RhjuYrev7sjXkVelIgV+U+bPg9WrWjX+9esa2sAZj5a parA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from:sender :dkim-signature:arc-authentication-results; bh=6oR8SX/Ju15dFyQkrGmkBtdzRaqiBq4O7cLvGw4B2i4=; b=xT6+AePWtLNA+6Jp9NdOkOMMe/AWmCz+3yIKmZDILM70QdOz20vmuRO339HkLJunSw 2plf0rJAm+D1kalj9RyRhq68Aj3WZVwGyC07qdAASRnFatKl/Ahtjvjwm1MQdEOlkCLA +F84HStrketu3YKEOlGc/jApkLjabMLUEBE/N4/60zpsXD34oBmxSxWxG7i4Y1yuytIf Wl/NZc5/9jyOd5lKqgSQRU1zuoC0oPZFewLlJtNAfnmUMATum4fH0U5oH2Y80Ii4fhU4 M7YdlLRwMILgKrbk+iGPM4g6nfuvjeGt9SKx8kqTYhI6HI8dRW7wl2QweVRIQXhTq93p e9tw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=npsBj+sn; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id q30-v6sor2099620qkh.138.2018.06.13.17.47.28 for (Google Transport Security); Wed, 13 Jun 2018 17:47:28 -0700 (PDT) Received-SPF: pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=npsBj+sn; spf=pass (google.com: domain of ram.n.pai@gmail.com designates 209.85.220.65 as permitted sender) smtp.mailfrom=ram.n.pai@gmail.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com 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=6oR8SX/Ju15dFyQkrGmkBtdzRaqiBq4O7cLvGw4B2i4=; b=npsBj+snAWlJWpEH4cqBs3EMpJjEY9e0H5XZaywmN94mcr1n2QwvS3+oYTKxRlU+dn +u/7e3n1apa3IDsXDQJyrm6WRdjEQU6rlSklIa4T898uXUmhx/frHBSIwLKn623o0gR2 +0mS1JsNBe5eXKHegk5HTK0so4IJP9s1QGMJfoThOHaVGH8Kr81cBiIMBkbq3XbGgUFm /Eh3CaW0vPQIh6y1qwPoIvK4VvadOtaUVUUM0g7YokQ5HfLv6JFNJEbFPWbrhfIijHHN W4gNX5pYo+R8Lfj7vPGHtEklc0dh3LSvCV5DDgtZHiVWKMujgKb1/RRqj7JBK+Y30040 Nc1w== X-Google-Smtp-Source: ADUXVKLLVVsJ9P98WPNLeImv98D2qO9mnN4iTfdRkkTYfpOPUpzZdgtZ59K6dG7M00wI91K8dz2bHg== X-Received: by 2002:ae9:c008:: with SMTP id u8-v6mr361105qkk.85.1528937248353; Wed, 13 Jun 2018 17:47:28 -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 u31-v6sm3225898qtc.28.2018.06.13.17.47.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:27 -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 v13 22/24] selftests/vm: testcases must restore pkey-permissions Date: Wed, 13 Jun 2018 17:45:13 -0700 Message-Id: <1528937115-10132-23-git-send-email-linuxram@us.ibm.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> References: <1528937115-10132-1-git-send-email-linuxram@us.ibm.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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. The test case is responsible for restoring the key register state to its original value. 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 caf634e..b5a9e6c 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1011,6 +1011,7 @@ void test_read_of_write_disabled_region(int *ptr, u16 pkey) ptr_contents = read_ptr(ptr); dprintf1("*ptr: %d\n", ptr_contents); dprintf1("\n"); + pkey_write_allow(pkey); } void test_read_of_access_disabled_region(int *ptr, u16 pkey) { @@ -1090,6 +1091,7 @@ void test_kernel_write_of_access_disabled_region(int *ptr, u16 pkey) ret = read(test_fd, ptr, 1); dprintf1("read ret: %d\n", ret); pkey_assert(ret); + pkey_access_allow(pkey); } void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) { @@ -1102,6 +1104,7 @@ void test_kernel_write_of_write_disabled_region(int *ptr, u16 pkey) if (ret < 0 && (DEBUG_LEVEL > 0)) perror("verbose read result (OK for this to be bad)"); pkey_assert(ret); + pkey_write_allow(pkey); } void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) @@ -1121,6 +1124,7 @@ void test_kernel_gup_of_access_disabled_region(int *ptr, u16 pkey) vmsplice_ret = vmsplice(pipe_fds[1], &iov, 1, SPLICE_F_GIFT); dprintf1("vmsplice() ret: %d\n", vmsplice_ret); pkey_assert(vmsplice_ret == -1); + pkey_access_allow(pkey); close(pipe_fds[0]); close(pipe_fds[1]); @@ -1141,6 +1145,7 @@ void test_kernel_gup_write_to_write_disabled_region(int *ptr, u16 pkey) if (DEBUG_LEVEL > 0) perror("futex"); dprintf1("futex() ret: %d\n", futex_ret); + pkey_write_allow(pkey); } /* Assumes that all pkeys other than 'pkey' are unallocated */