Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2370977imm; Thu, 18 Oct 2018 13:31:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV60iHVh1K2wzTBjGwvzkbeLIhTo0V4V4e/ar7V6SNkBK7FyxF1iZhlCsL8ktGB6QVOUbARMH X-Received: by 2002:a62:1407:: with SMTP id 7-v6mr31276589pfu.28.1539894698744; Thu, 18 Oct 2018 13:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539894698; cv=none; d=google.com; s=arc-20160816; b=lCnOTaznPSHxhxWlvLOGjpeYKlufmUfZQEuM6HTXc+tfopVbS0GVlMZb5Dea1cHCHI Eq3TySpQDY+8bgdMeZqc6EybF+w3RfduKE4sVSaKcT5/t3nCV0Hk0YQonLv7tt8FzNbk AqqnEHDPQTal3ET7N/BCUVVIRDEnbczQ62fAYDctpUzEa4soOJhhvy/LOVaey+9FWiig Y1mMydULu7pR7lPKyEQ3imqyXfx5kz2fTdOmM98nWSL8SRAb5PNh104bcLvmd1ueol9d jjbc5zI6BJxQeIOp6nSBu00rRgZ61xro32MUjiUTj1w87J43K3S1VrDNgiKaDA23ZI6K zl7A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=w8j88j2GAoqg2PkEbx7YnmE164Wwv6hXB/O5DW8v5CE=; b=RgOsLg8qA5qAIidqEgFYRNLD6icguFLFeC4mxyZ/DxZRPQ+OiEOXUMPXaK8asHbfRa xL5OAZ253gXok7jg46xSCcyQckAKwbAuzzmGt+O9hlHAFIB6CwG3fO2wuzfcQ9b8V/Jr bd9Ruci4eoWExvvCLj+QzQNWqvNyyw2bkcYbKd964vLqefO3jlMgmBrbZ2xPIqU/wLxr Fsfh8yQUZYPe7ZDTp7rA8F68+nQqbw9tXqqM/mgFBMmMFQ/7NoHZN7EM38zQSF6N+E3I WJqESfQ3D9AUEGZeQsOBjqXA9SO3brb8IFkkmYnYUkzyP03r+Du7vPYwHM050lA7HssZ B5bg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3-v6si22395129pga.369.2018.10.18.13.31.23; Thu, 18 Oct 2018 13:31:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727014AbeJSEEE (ORCPT + 99 others); Fri, 19 Oct 2018 00:04:04 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35382 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725751AbeJSEEE (ORCPT ); Fri, 19 Oct 2018 00:04:04 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7C7D3753E8; Thu, 18 Oct 2018 20:01:28 +0000 (UTC) Received: from localhost (unknown [10.18.25.149]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 210BA105704D; Thu, 18 Oct 2018 20:01:25 +0000 (UTC) Date: Thu, 18 Oct 2018 16:01:25 -0400 From: Mike Snitzer To: Vitaly Chikunov Cc: Alasdair Kergon , dm-devel@redhat.com, Jonathan Corbet , Shaohua Li , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-raid@vger.kernel.org Subject: Re: dm: add secdel target Message-ID: <20181018200124.GA6996@redhat.com> References: <20181014112439.8119-1-vt@altlinux.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20181014112439.8119-1-vt@altlinux.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Thu, 18 Oct 2018 20:01:28 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Oct 14 2018 at 7:24am -0400, Vitaly Chikunov wrote: > Report to the upper level ability to discard, and translate arriving > discards to the writes of random or zero data to the underlying level. > > Signed-off-by: Vitaly Chikunov > --- > This target is the same as the linear target except that is reports ability to > discard to the upper level and translates arriving discards into sector > overwrites with random (or zero) data. There is a fair amount of code duplication between dm-linear.c and this new target. Something needs to give, ideally you'd factor out methods that are shared by both targets, but those methods must _not_ introduce overhead to dm-linear. Could be that dm-linear methods just get called by the wrapper dm-sec-erase target (more on the "dm-sec-erase" name below). > The target does not try to determine if the underlying drive reliably supports > data overwrites, this decision is solely on the discretion of a user. > > It may be useful to create a secure deletion setup when filesystem when > unlinking a file sends discards to its sectors, in this target they are > translated to writes that wipe deleted data on the underlying drive. > > Tested on x86. All of this extra context and explanation needs to be captured in the actual patch header. Not as a tangent in that "cut" section of your patch header. > Documentation/device-mapper/dm-secdel.txt | 24 ++ > drivers/md/Kconfig | 14 ++ > drivers/md/Makefile | 2 + > drivers/md/dm-secdel.c | 399 ++++++++++++++++++++++++++++++ > 4 files changed, 439 insertions(+) > create mode 100644 Documentation/device-mapper/dm-secdel.txt > create mode 100644 drivers/md/dm-secdel.c Shouldn't this target be implementing all that is needed for REQ_OP_SECURE_ERASE support? And the resulting DM device would advertise its capability using QUEUE_FLAG_SECERASE? And this is why I think the target should be named "dm-sec-erase" or even "dm-secure-erase". > diff --git a/drivers/md/dm-secdel.c b/drivers/md/dm-secdel.c > new file mode 100644 > index 000000000000..9aeaf3f243c0 > --- /dev/null > +++ b/drivers/md/dm-secdel.c > +/* > + * Send amount of masking data to the device > + * @mode: 0 to write zeros, otherwise to write random data > + */ > +static int issue_erase(struct block_device *bdev, sector_t sector, > + sector_t nr_sects, gfp_t gfp_mask, enum secdel_mode mode) > +{ > + int ret = 0; > + > + while (nr_sects) { > + struct bio *bio; > + unsigned int nrvecs = min(nr_sects, > + (sector_t)BIO_MAX_PAGES >> 3); > + > + bio = bio_alloc(gfp_mask, nrvecs); You should probably be using your own bioset to allocate these bios. > + if (!bio) { > + DMERR("%s %lu[%lu]: no memory to allocate bio (%u)", > + __func__, sector, nr_sects, nrvecs); > + ret = -ENOMEM; > + break; > + } > + > + bio->bi_iter.bi_sector = sector; > + bio_set_dev(bio, bdev); > + bio->bi_end_io = bio_end_erase; > + > + while (nr_sects != 0) { > + unsigned int sn; > + struct page *page = NULL; > + > + sn = min((sector_t)PAGE_SIZE >> 9, nr_sects); > + if (mode == SECDEL_MODE_RAND) { > + page = alloc_page(gfp_mask); > + if (!page) { > + DMERR("%s %lu[%lu]: no memory to allocate page for random data", > + __func__, sector, nr_sects); > + /* will fallback to zero filling */ In general, performing memory allocations to service IO is something all DM core and DM targets must work to avoid. This smells bad. ... > + > +/* convert discards into writes */ > +static int secdel_map_discard(struct dm_target *ti, struct bio *sbio) > +{ > + struct secdel_c *lc = ti->private; > + struct block_device *bdev = lc->dev->bdev; > + sector_t sector = sbio->bi_iter.bi_sector; > + sector_t nr_sects = bio_sectors(sbio); > + > + lc->requests++; > + if (!bio_sectors(sbio)) > + return 0; > + if (!op_discard(sbio)) > + return 0; > + lc->discards++; > + if (WARN_ON(sbio->bi_vcnt != 0)) > + return -1; > + DMDEBUG("DISCARD %lu: %u sectors M%d", sbio->bi_iter.bi_sector, > + bio_sectors(sbio), lc->mode); > + bio_endio(sbio); > + > + if (issue_erase(bdev, sector, nr_sects, GFP_NOFS, lc->mode)) At a minimum this should be GFP_NOIO. You don't want to recurse into block (and potentially yourself) in the face of low memory. > +static int secdel_end_io(struct dm_target *ti, struct bio *bio, > + blk_status_t *error) > +{ > + struct secdel_c *lc = ti->private; > + > + if (!*error && bio_op(bio) == REQ_OP_ZONE_REPORT) > + dm_remap_zone_report(ti, bio, lc->start); > + > + return DM_ENDIO_DONE; > +} Perfect example of why this new target shouldn't be doing a point in time copy of dm-linear code. With 4.20's upcoming zoned device changes dm-linear no longer even has an end_io hook (which was introduced purely for REQ_OP_ZONE_REPORT's benefit). Mike