From patchwork Fri Jun 21 03:00:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geremy Condra X-Patchwork-Id: 2759961 X-Patchwork-Delegate: agk@redhat.com Return-Path: X-Original-To: patchwork-dm-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id C5BDF9F756 for ; Fri, 21 Jun 2013 03:04:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7D8C320163 for ; Fri, 21 Jun 2013 03:04:57 +0000 (UTC) Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mail.kernel.org (Postfix) with ESMTP id E9AD62015E for ; Fri, 21 Jun 2013 03:04:55 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5L30suI022985; Thu, 20 Jun 2013 23:00:56 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id r5L30psZ005657 for ; Thu, 20 Jun 2013 23:00:51 -0400 Received: from mx1.redhat.com (ext-mx15.extmail.prod.ext.phx2.redhat.com [10.5.110.20]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r5L30pbs027505 for ; Thu, 20 Jun 2013 23:00:51 -0400 Received: from mail-pa0-f41.google.com (mail-pa0-f41.google.com [209.85.220.41]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r5L30nIg016020 for ; Thu, 20 Jun 2013 23:00:50 -0400 Received: by mail-pa0-f41.google.com with SMTP id bj3so7138304pad.14 for ; Thu, 20 Jun 2013 20:00:49 -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=1KsxfM/vjE+fmKI2isCt6NjhZ1/ao83N+KoiVJCuzRA=; b=lTmGT3hNRay33f56aDu89DVNfrxXrtdUn4e1WA8NZNkDDe3hijRS83mknw/vp0QVNo 2IKYHlDgGNo4h38lhE2EuNn6Sg6alDuiBxd0U0HYJ94SwETvHYsfno82gYkU79e07tSZ 922B4aqf+FfBNti4+jtYjj2IsYyocpVl3EK53lKoQEeNDIQ9dRotD1pXMj9AN6idd+N2 8PWW3c92BUPZdBYVjVZiOO2eZfQ4rIpKfkTIQdB+1EHgIFj/aXQybAqgYFSkUYt1YkTO OI7kAN6ohPJmJjtRYsU76sgYs5K5LTv5L/87hZHVyq4R5EBkHecu7cHMe5Nv2uPNLs9F cYqg== 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=1KsxfM/vjE+fmKI2isCt6NjhZ1/ao83N+KoiVJCuzRA=; b=YMV9m/SnJj2IxNf3L+dp5TXd9BesoxVqz/WmPSZjk76lrel3WPay7v15rUtTn8xA45 Ib2ZPtPV76Ft46XZ8KMIT4eoNDtjWyTuH8mqPQ19z8AZVLbon5hbsgUP4SDYTirq33W5 zWaGRYsx6MQOqt5Bsm/APrtb05taMxVCn+DT6TO84NXPEltXyK0A0B+dssI7cXjeGcHG Q/R2QwCOZTQsRwI6/NTlNo0VGucvxXtmOe36+Aq2tr+Ixk5ZxIG1AIA8ZDDpMFDzLsJr zxi2GGdN24Bo+UGlSKPgHoIlR64csT25tLw3WhSbkF1vcUSLe8/ADyVKRdF81r3btu5U hhKg== X-Received: by 10.66.27.147 with SMTP id t19mr14031576pag.171.1371783649380; Thu, 20 Jun 2013 20:00:49 -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 xl3sm2758550pbb.17.2013.06.20.20.00.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 20 Jun 2013 20:00:48 -0700 (PDT) From: Geremy Condra To: dm-devel@redhat.com Date: Thu, 20 Jun 2013 20:00:24 -0700 Message-Id: <1371783624-23962-1-git-send-email-gcondra@google.com> X-Gm-Message-State: ALoCoQkuDsSH7U8XDFrFKQi9EYp4aN9cnGVrwgTsA1HIw1igL91INXAy2cxUofqZiJFLkPBViTTl+Fnv7+4OrDUcwpTQ1ATWkbwscsHUNDwiZJk7QQzsH0zFCuQk3qhgstInf89UF6F/rK+iqAunyOpZk0Zc2pcFLP0+69Q1T6c7oRqKdkIbdVZny7EjqUEGjO5u5KVX2wmVp3fdoquEN9uymLpXqtbhuZ9EFzs4pQsedbZDHVZ8XOU= 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.24 X-Scanned-By: MIMEDefang 2.68 on 10.5.110.20 X-loop: dm-devel@redhat.com Cc: wad@chromium.org, linux-kernel@vger.kernel.org, agk@redhat.com, Geremy Condra Subject: [dm-devel] [PATCH v2] 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 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 Acked-by: Will Drewry --- Changelog since v1: - Removed the DM_VERITY_ERROR_NOTIFY config option drivers/md/dm-uevent.c | 40 ++++++++++++++++++++++++++++++++++++++++ drivers/md/dm-uevent.h | 12 ++++++++++-- drivers/md/dm-verity.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 2 deletions(-) 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..2e3695b 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_UEVENT +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; } }