From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oo1-f43.google.com (mail-oo1-f43.google.com [209.85.161.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 297541B273 for ; Sat, 2 Mar 2024 16:13:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.43 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709395997; cv=none; b=WwfTrcT8UmgkWzQaHxSBVFApimc/EmAPSPALyw+KAL7kLoVFuGSflBuQpoBOy2D3k7nAGpVp1AYaqSXAj1BMqbYd5Q4klU2IXsfEhn5+OxwnrxulOIEA/vm/QJu40czuwCB8vfz0iEYD2D9VyBQyVhTmdPSSwdopYKZQaVmGCts= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709395997; c=relaxed/simple; bh=FbjTuTWqBDQsWRS0dZyGAKYtWVxCCDP+Jy5p1Tkb6xY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=MLcFhPpft+TrN5oU4LQxl10oRlj0Pm7ktHUWLRaX/Bfi782CzkqNAIyZs/4lZ/Z+HL+bUYfOm8bR3D8OUVigOPemCNHhm8Ua2EKHQhdsH+q6WEex053R0kARpILGm8HB2UC3GfY1XCR2RXZVTc/cWqHGjq0mVqn+OPvP1/wN2jM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=redhat.com; arc=none smtp.client-ip=209.85.161.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Received: by mail-oo1-f43.google.com with SMTP id 006d021491bc7-5a11dea5bbaso239320eaf.2 for ; Sat, 02 Mar 2024 08:13:13 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709395993; x=1710000793; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=9z4aaL+eoV7uAuWVMK9/aYASmrv+Wksdp8IvJ6mzxpQ=; b=Y1RI5s+4U6cjKTSyi/0EJHjqJ2pfPMkITo6DPCF3hrodJFbdRv30dJ5mWe9htdQ6h8 2YTeDRPue4n9bGLH7umWBmpA+gyCswQs21FgOlFcFjhVEQK1mfwb6cfp7nRYdwPJjWTL Zi/3ezvULCi+0RXVUa9L9C7ciY6kw1F/LxFywV2UJ5PaKx1BbQcvHD9Tr+d/mB9UzVn5 xcEoOiZt4ItSj1c8zkdo9HyojZoh1lFGkVnB8EH6GGI0ZIOJTe/I0vLfSix/t2a+QiQU VUfZULeaB6KPEvrMEx7DNVCvlrdqeNvQNZqZ9CvSUJouCJPIYn3Y3ck4yCnkN8/6+4o6 BsBA== X-Forwarded-Encrypted: i=1; AJvYcCU/goR+sCNUbYwUl6ygbMv3og/7ty4QYJLQK6lSs4ROuH5bqPdslqGWoTmPd3Idg5Q8rddgOJS5g1N5QxQQuXTILaNwOwS/FuFkR8D/jgMv9uBNaK4D X-Gm-Message-State: AOJu0YwIv588xgAvFpYuMOVpx8gNo149/KCZd4I/9hPD/pyMTcZHSR+v Xd+6l/NRl0PUXfggJJ8Ebq/WzfXEY+CvxzcPvCIA9O1e+JuZD+085lkEHV21+ysbLPj0upPi4bU = X-Google-Smtp-Source: AGHT+IGf9jgOeoj362uKhi105PtehqMD4txWWxwWyWfRjF/hG3odid6G8dwTAJ8IfpCY0YN3OcPPAA== X-Received: by 2002:a05:6358:181:b0:17b:eec9:8ee8 with SMTP id d1-20020a056358018100b0017beec98ee8mr4991319rwa.12.1709395993108; Sat, 02 Mar 2024 08:13:13 -0800 (PST) Received: from localhost (pool-68-160-141-91.bstnma.fios.verizon.net. [68.160.141.91]) by smtp.gmail.com with ESMTPSA id kr9-20020a0562142b8900b0068fcd643b9dsm3093596qvb.22.2024.03.02.08.13.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 02 Mar 2024 08:13:12 -0800 (PST) Date: Sat, 2 Mar 2024 11:13:10 -0500 From: Mike Snitzer To: Fan Wu Cc: corbet@lwn.net, zohar@linux.ibm.com, jmorris@namei.org, serge@hallyn.com, tytso@mit.edu, ebiggers@kernel.org, axboe@kernel.dk, agk@redhat.com, eparis@redhat.com, paul@paul-moore.com, linux-doc@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fscrypt@vger.kernel.org, linux-block@vger.kernel.org, dm-devel@lists.linux.dev, audit@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v13 13/20] dm: add finalize hook to target_type Message-ID: References: <1709168102-7677-1-git-send-email-wufan@linux.microsoft.com> <1709168102-7677-14-git-send-email-wufan@linux.microsoft.com> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1709168102-7677-14-git-send-email-wufan@linux.microsoft.com> On Wed, Feb 28 2024 at 7:54P -0500, Fan Wu wrote: > This patch adds a target finalize hook. > > The hook is triggered just before activating an inactive table of a > mapped device. If it returns an error the __bind get cancelled. > > The dm-verity target will use this hook to attach the dm-verity's > roothash metadata to the block_device struct of the mapped device. > > Signed-off-by: Fan Wu > > --- > v1-v10: > + Not present > > v11: > + Introduced > > v12: > + No changes > > v13: > + No changes > --- > drivers/md/dm.c | 12 ++++++++++++ > include/linux/device-mapper.h | 7 +++++++ > 2 files changed, 19 insertions(+) > > diff --git a/drivers/md/dm.c b/drivers/md/dm.c > index 8dcabf84d866..15b46edae49f 100644 > --- a/drivers/md/dm.c > +++ b/drivers/md/dm.c > @@ -2266,6 +2266,18 @@ static struct dm_table *__bind(struct mapped_device *md, struct dm_table *t, > goto out; > } > > + for (unsigned int i = 0; i < t->num_targets; i++) { > + struct dm_target *ti = dm_table_get_target(t, i); > + > + if (ti->type->finalize) { > + ret = ti->type->finalize(ti); > + if (ret) { > + old_map = ERR_PTR(ret); > + goto out; > + } > + } > + } > + > old_map = rcu_dereference_protected(md->map, lockdep_is_held(&md->suspend_lock)); > rcu_assign_pointer(md->map, (void *)t); > md->immutable_target_type = dm_table_get_immutable_target_type(t); > diff --git a/include/linux/device-mapper.h b/include/linux/device-mapper.h > index 772ab4d74d94..627400b2d9af 100644 > --- a/include/linux/device-mapper.h > +++ b/include/linux/device-mapper.h > @@ -160,6 +160,12 @@ typedef int (*dm_dax_zero_page_range_fn)(struct dm_target *ti, pgoff_t pgoff, > */ > typedef size_t (*dm_dax_recovery_write_fn)(struct dm_target *ti, pgoff_t pgoff, > void *addr, size_t bytes, struct iov_iter *i); > +/* > + * Returns: > + * < 0 : error > + * = 0 : success > + */ > +typedef int (*dm_finalize_fn) (struct dm_target *target); This needs some documentation, e.g.: this hook allows DM targets in an inactive table to complete their setup before the table is made active. Mike > > void dm_error(const char *message); > > @@ -210,6 +216,7 @@ struct target_type { > dm_dax_direct_access_fn direct_access; > dm_dax_zero_page_range_fn dax_zero_page_range; > dm_dax_recovery_write_fn dax_recovery_write; > + dm_finalize_fn finalize; > > /* For internal device-mapper use. */ > struct list_head list; > -- > 2.43.1 > >