From patchwork Thu Jun 14 00:45:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ram Pai X-Patchwork-Id: 929204 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 415mWr6Qv7z9s2g for ; Thu, 14 Jun 2018 11:39:52 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aqI92FA2"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 415mWr4smxzF0XQ for ; Thu, 14 Jun 2018 11:39:52 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aqI92FA2"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:400d:c0d::241; helo=mail-qt0-x241.google.com; envelope-from=ram.n.pai@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=us.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aqI92FA2"; dkim-atps=neutral Received: from mail-qt0-x241.google.com (mail-qt0-x241.google.com [IPv6:2607:f8b0:400d:c0d::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 415lML1zswzF0Pd for ; Thu, 14 Jun 2018 10:47:26 +1000 (AEST) Received: by mail-qt0-x241.google.com with SMTP id i18-v6so4252121qtp.12 for ; Wed, 13 Jun 2018 17:47:26 -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=M3yd2j8AWo3Al67AL1nh96ezYjVo52Tv/5lV+JNm2kQ=; b=aqI92FA2XbuvsMyC06jnkkWSleKSzLUEf7SQB22LFLEByyV/SOARQPjap540eLY3fZ Gj98AvKouDjmGgyO6ubrpCMY+DxN/XLldM1N5BDxgkhfwLj9BmI7hZxtVcC6cpb7XKGh i98srcTC/u8rC0NpZsMXF8nPMG7n6GlW11mtYAudJBQ0Jj3WOJf0flecy+r+YV1A/hAO JqNZvqbb7ZOAJoGQtGwo3FTs5EDfcBxMX92m0dyozDtW032SvVxihIjd3tpyE9UZX7bJ h2c5FNR8fLecqe/ZVeuVQR18ZyPw5wu4fqzwYNCGUDWd0wZO/k1IRLwa5diunXKfshHR 7dWg== 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=M3yd2j8AWo3Al67AL1nh96ezYjVo52Tv/5lV+JNm2kQ=; b=H5KuA+tZIZWArX81g7gKni1a3e60j5R2mo441TVHtA8ACto6A3xEH4BH+YRCJJmA/d J3UbWaz8KaCVxnWLF8TbmHSHTgD5Ly4H10s3bo3KiGZ98EPjAN+4Kyw6h1JzNVI5iOn5 gT4hDJB4GbqKx7tv1db/e1R05uv0ryYlYNp3O54R1Q2F0yx0y4PYy1fEDFYeBf3PAN0m E7qsGZ/5OygXjbs8xEDnS8vTOwhFt1WK49qbzMP5yd9tKFgNEYYpUUmd2nuWQH3x+/w6 qvomsfYq3azb7ujccfAZdKqmwR4v2r2Z6f/joEGV+qwVqkabnix/6m7GwefgG6yIake4 qikQ== X-Gm-Message-State: APt69E3TQfXhfMFeJfq7sfFbFUlwJpARuDUeek5qFVidW5hnnVjKOgXx 9I5JvmbTBDxI8On5lhJmJYY= X-Google-Smtp-Source: ADUXVKJWpXN+ccjsiGq19O0ny10KfYlaEhHbnGP174ZF/j40/f6L6Jqp0Sm4C63wsQzukemvbRZl0w== X-Received: by 2002:a0c:9273:: with SMTP id 48-v6mr373605qvz.220.1528937244243; Wed, 13 Jun 2018 17:47:24 -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.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jun 2018 17:47:23 -0700 (PDT) From: Ram Pai To: shuahkh@osg.samsung.com, linux-kselftest@vger.kernel.org Subject: [PATCH v13 20/24] selftests/vm: associate key on a mapped page and detect write violation Date: Wed, 13 Jun 2018 17:45:11 -0700 Message-Id: <1528937115-10132-21-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-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, fweimer@redhat.com, dave.hansen@intel.com, x86@kernel.org, linuxram@us.ibm.com, mhocko@kernel.org, linux-mm@kvack.org, mingo@redhat.com, aneesh.kumar@linux.vnet.ibm.com, bauerman@linux.vnet.ibm.com, msuchanek@suse.de, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" detect write-violation on a page to which write-disabled key is associated much after the page is mapped. cc: Dave Hansen cc: Florian Weimer Signed-off-by: Ram Pai Acked-by: Dave Hansen --- tools/testing/selftests/vm/protection_keys.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/tools/testing/selftests/vm/protection_keys.c b/tools/testing/selftests/vm/protection_keys.c index 04d0249..f4acd72 100644 --- a/tools/testing/selftests/vm/protection_keys.c +++ b/tools/testing/selftests/vm/protection_keys.c @@ -1042,6 +1042,17 @@ void test_read_of_access_disabled_region_with_page_already_mapped(int *ptr, expected_pkey_fault(pkey); } +void test_write_of_write_disabled_region_with_page_already_mapped(int *ptr, + u16 pkey) +{ + *ptr = __LINE__; + dprintf1("disabling write access; after accessing the page, " + "to PKEY[%02d], doing write\n", pkey); + pkey_write_deny(pkey); + *ptr = __LINE__; + expected_pkey_fault(pkey); +} + void test_write_of_write_disabled_region(int *ptr, u16 pkey) { dprintf1("disabling write access to PKEY[%02d], doing write\n", pkey); @@ -1422,6 +1433,7 @@ void test_mprotect_pkey_on_unsupported_cpu(int *ptr, u16 pkey) test_read_of_access_disabled_region, test_read_of_access_disabled_region_with_page_already_mapped, test_write_of_write_disabled_region, + test_write_of_write_disabled_region_with_page_already_mapped, test_write_of_access_disabled_region, test_kernel_write_of_access_disabled_region, test_kernel_write_of_write_disabled_region,