From patchwork Thu Jun 20 21:21:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geremy Condra X-Patchwork-Id: 2758721 Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 7623CC0AB1 for ; Thu, 20 Jun 2013 21:26:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3B724200F9 for ; Thu, 20 Jun 2013 21:26:05 +0000 (UTC) Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by mail.kernel.org (Postfix) with ESMTP id 2ED772013B for ; Thu, 20 Jun 2013 21:26:04 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5KLLlpO031107; Thu, 20 Jun 2013 17:21:49 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5KLLjkC008317 for ; Thu, 20 Jun 2013 17:21:45 -0400 Received: from mx1.redhat.com (ext-mx14.extmail.prod.ext.phx2.redhat.com [10.5.110.19]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5KLLjXe017709 for ; Thu, 20 Jun 2013 17:21:45 -0400 Received: from mail-pa0-f46.google.com (mail-pa0-f46.google.com [209.85.220.46]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5KLLiPW009566 for ; Thu, 20 Jun 2013 17:21:44 -0400 Received: by mail-pa0-f46.google.com with SMTP id fa11so6764333pad.33 for ; Thu, 20 Jun 2013 14:21:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=V+ZCiJw9TLbtr7Qd46aXzzrSczuwPMirdNXXnjncxJM=; b=FYyW9wbXRtyTaaA8EKvwS5elgqFxHgoAIpywoAhK9i3n5gOoc3OIedqWAnfVvgEY4h 4+pEo0bF7KcwXd4BxlLUUpkeUjGv8IPBKKDoXnUuuwXWNHJkrIPBie7nhEoRpwFqsBlo QKEUKTb/hwqTo4IaDGWmSjVJQaOq8AGNRUWMAuKugFUofnJKvaA7HNVMiY33Ij/8n+KM YvTiHq8wqSTI3kBYSyAR4dTjKiC7t9DgmuoosCM8Z2H1RXaHwue0mkH2MYLB1zjMNAhv +64sSDawfP2kkZdyPRXl9yqOWgQQ41w/mjjVYoF/lDs9OTHsmSkM8dJ83PVIDM75/D45 /0sA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:x-gm-message-state; bh=V+ZCiJw9TLbtr7Qd46aXzzrSczuwPMirdNXXnjncxJM=; b=L6EmBIj2N1/S7GepOD+0FjQm+v1JhGVdWKiNKShrTRyG0BJr5QHSl8PyxAJzyJc55/ zXVBWcwnF6s5XFk3IVKDvZCgiAaJkiTyoui9tUJNybo6/kU8qozpVXku1hCvLJ/xJNPU qeAYognxwSGzPntTTbOKFIZ5LCH8Wo0x7mDJwGqffU3f/TszhhDX7VtGXomE+MZpRy4P sqHG25Y34PXWpu0k83GhM3IPNkqTFv8JFaBlGqZ0fpz2d4XIgTEC2PB2GrvG/9F3j+q+ bb5enGqlUMkCof3DuD7RlO3l4M3kBE4VtkTWk1VdGR/ya0+dj9EcO3Dd+R4C3QHnDxH4 xv9g== X-Received: by 10.66.219.103 with SMTP id pn7mr13152413pac.123.1371763303699; Thu, 20 Jun 2013 14:21:43 -0700 (PDT) Received: from gcc.mtv.corp.google.com (gcc.mtv.corp.google.com [172.18.100.148]) by mx.google.com with ESMTPSA id qi1sm2300141pac.21.2013.06.20.14.21.41 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Jun 2013 14:21:42 -0700 (PDT) From: Geremy Condra To: dm-devel@redhat.com Date: Thu, 20 Jun 2013 14:21:00 -0700 Message-Id: <1371763260-9933-1-git-send-email-gcondra@google.com> X-Gm-Message-State: ALoCoQnGvc4zDsdaOptzj4rfRSYoL6zZ+9RYbTT0MSQg38NvMmLj3IXI0miqDOBiCgNPiItSgkVYCw/jdleH0otPnBYEgVSD8LmDG3hcQFoo0Vj6zB9/8uOI5zYneC8fomN4Rr7rMPQ0VEnuz5I/k9aliKczrP1CelSbVPEzd9Rb6k8XFOIgw+U4a0dnNEPNGBD509BqC9MRF+aVpTHNs1EsjUy4dpHGbTwjPvV7aYsIn3BjoC4BDqQ= X-RedHat-Spam-Score: -3.998 (BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, SPF_PASS) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.19 X-loop: dm-devel@redhat.com Cc: wad@chromium.org, linux-kernel@vger.kernel.org, agk@redhat.com, Geremy Condra Subject: [dm-devel] [PATCH] dm: verity: Add support for emitting uevents on dm-verity errors. X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP With this change and config option, dm-verity errors will cause uevents to be sent to userspace, notifying it that an error has occurred and potentially triggering recovery actions. Signed-off-by: Geremy Condra Change-Id: If3d9c00770d1a640faa0d42318cce675da40c000 --- drivers/md/Kconfig | 6 ++++++ drivers/md/dm-uevent.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/md/dm-uevent.h | 12 ++++++++++-- drivers/md/dm-verity.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 84 insertions(+), 2 deletions(-) diff --git a/drivers/md/Kconfig b/drivers/md/Kconfig index 10f122a..fab9c32 100644 --- a/drivers/md/Kconfig +++ b/drivers/md/Kconfig @@ -390,4 +390,10 @@ config DM_VERITY If unsure, say N. +config DM_VERITY_ERROR_NOTIFY + tristate "Notify userspace of verity errors through uevents" + depends on DM_VERITY && DM_UEVENT + ---help--- + This option instructs dm-verity to send uevents on error. + endif # MD diff --git a/drivers/md/dm-uevent.c b/drivers/md/dm-uevent.c index 8efe033..17a6662 100644 --- a/drivers/md/dm-uevent.c +++ b/drivers/md/dm-uevent.c @@ -36,6 +36,8 @@ static const struct { } _dm_uevent_type_names[] = { {DM_UEVENT_PATH_FAILED, KOBJ_CHANGE, "PATH_FAILED"}, {DM_UEVENT_PATH_REINSTATED, KOBJ_CHANGE, "PATH_REINSTATED"}, + {DM_UEVENT_VERITY_DATA_ERROR, KOBJ_CHANGE, "VERITY_DATA_ERROR"}, + {DM_UEVENT_VERITY_HASH_ERROR, KOBJ_CHANGE, "VERITY_HASH_ERROR"}, }; static struct kmem_cache *_dm_event_cache; @@ -202,6 +204,44 @@ void dm_path_uevent(enum dm_uevent_type event_type, struct dm_target *ti, } EXPORT_SYMBOL_GPL(dm_path_uevent); +void dm_send_verity_uevent(enum dm_uevent_type event_type, struct dm_target *ti, + unsigned long long block_nr) +{ + struct mapped_device *md = dm_table_get_md(ti->table); + struct dm_uevent *event = dm_uevent_alloc(md); + struct gendisk *disk = dm_disk(md); + + if (!event) { + DMERR("%s: dm_uevent_alloc() failed", __func__); + return; + } + + if (event_type >= ARRAY_SIZE(_dm_uevent_type_names)) { + DMERR("%s: Invalid event_type %d", __func__, event_type); + goto out; + } + + if (add_uevent_var(&event->ku_env, "DM_VERITY_BLOCK_NR=%llu", block_nr)) { + DMERR("%s: add_uevent_var() for DM_VERITY_BLOCK failed", __func__); + goto out; + } + + if (add_uevent_var(&event->ku_env, "DM_ACTION=%s", + _dm_uevent_type_names[event_type].name)) { + DMERR("%s: add_uevent_var() for DM_ACTION failed", __func__); + goto out; + } + + if (kobject_uevent_env(&disk_to_dev(disk)->kobj, event_type, + event->ku_env.envp)) { + DMERR("%s: kobject_uevent_env failed", __func__); + } + +out: + dm_uevent_free(event); +} +EXPORT_SYMBOL_GPL(dm_send_verity_uevent); + int dm_uevent_init(void) { _dm_event_cache = KMEM_CACHE(dm_uevent, 0); diff --git a/drivers/md/dm-uevent.h b/drivers/md/dm-uevent.h index 2eccc8b..1c59dba 100644 --- a/drivers/md/dm-uevent.h +++ b/drivers/md/dm-uevent.h @@ -24,6 +24,8 @@ enum dm_uevent_type { DM_UEVENT_PATH_FAILED, DM_UEVENT_PATH_REINSTATED, + DM_UEVENT_VERITY_DATA_ERROR, + DM_UEVENT_VERITY_HASH_ERROR, }; #ifdef CONFIG_DM_UEVENT @@ -34,7 +36,9 @@ extern void dm_send_uevents(struct list_head *events, struct kobject *kobj); extern void dm_path_uevent(enum dm_uevent_type event_type, struct dm_target *ti, const char *path, unsigned nr_valid_paths); - +extern void dm_send_verity_uevent(enum dm_uevent_type event_type, + struct dm_target *ti, + unsigned long long block_nr); #else static inline int dm_uevent_init(void) @@ -53,7 +57,11 @@ static inline void dm_path_uevent(enum dm_uevent_type event_type, unsigned nr_valid_paths) { } - +static inline void dm_send_verity_uevent(enum dm_uevent_type event_type, + struct dm_target *ti, + unsigned long long block_nr) +{ +} #endif /* CONFIG_DM_UEVENT */ #endif /* DM_UEVENT_H */ diff --git a/drivers/md/dm-verity.c b/drivers/md/dm-verity.c index 68bf5c3..c9c9ecc 100644 --- a/drivers/md/dm-verity.c +++ b/drivers/md/dm-verity.c @@ -20,6 +20,8 @@ #include #include +#include "dm-uevent.h" + #define DM_MSG_PREFIX "verity" #define DM_VERITY_IO_VEC_INLINE 16 @@ -137,6 +139,30 @@ static void dm_bufio_alloc_callback(struct dm_buffer *buf) } /* + * Trigger userspace data corruption handler. + */ +#ifdef CONFIG_DM_VERITY_ERROR_NOTIFY +static void verity_data_error(struct dm_verity *v, unsigned long long block_nr) +{ + dm_send_verity_uevent(DM_UEVENT_VERITY_DATA_ERROR, v->ti, block_nr); +} + +static void verity_hash_error(struct dm_verity *v, unsigned long long block_nr) +{ + dm_send_verity_uevent(DM_UEVENT_VERITY_HASH_ERROR, v->ti, block_nr); +} +#else +static inline void verity_data_error(struct dm_verity *v, + unsigned long long block_nr) +{ +} +static inline void verity_hash_error(struct dm_verity *v, + unsigned long long block_nr) +{ +} +#endif + +/* * Translate input sector number to the sector number on the target device. */ static sector_t verity_map_sector(struct dm_verity *v, sector_t bi_sector) @@ -255,6 +281,7 @@ static int verity_verify_level(struct dm_verity_io *io, sector_t block, (unsigned long long)hash_block); v->hash_failed = 1; r = -EIO; + verity_hash_error(v, (unsigned long long)hash_block); goto release_ret_r; } else aux->hash_verified = 1; @@ -375,6 +402,7 @@ test_block_hash: DMERR_LIMIT("data block %llu is corrupted", (unsigned long long)(io->block + b)); v->hash_failed = 1; + verity_data_error(v, (unsigned long long)(io->block + b)); return -EIO; } }