Received: by 2002:a05:7412:1492:b0:e2:908c:2ebd with SMTP id s18csp114343rdh; Tue, 22 Aug 2023 14:31:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMrgRmLcvuvAtZPJeXcKG8dJ7EarGUkPD7jRXpzN2eJHzouigtZfdNUHw4AFNUPXSKqUAa X-Received: by 2002:a05:6512:282c:b0:4fb:889c:c53d with SMTP id cf44-20020a056512282c00b004fb889cc53dmr8837694lfb.10.1692739916390; Tue, 22 Aug 2023 14:31:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692739916; cv=none; d=google.com; s=arc-20160816; b=zknUZAjPkmCh150BfyOD9thlnoD1fW4ab7AfJr3HmOZVV7bFGgvpfyr7aSs+5SYReb W/ColIdOckR+5z0D833ObuTyR6h5zt3HhxZloCSj2Mevmp4F3OS/7tyuO8os6wMcUk5z ANF6GCUs1fuIEpCeSgNh6wBHwYHleTGn9NYXKUZp9JRPiRvNlVXMp5j5smk85n3VQAQZ MLuuGM+suCECN4FRgaLdcJkunWarupBmTd0xkVqoCEF3WhgKLUyW4v7P6LV7MtwipieS vlSn1yJ6EYuVbYN6B13NmX5HHrgoX6R7xzf/kSSXgtmBFqJtkNeFXkZSXJF7xQn63aCc bOCw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature:dkim-filter; bh=arqNRg4wGatPNmrOhmdLvrj5EQchfmRIhWqAHl91U0w=; fh=rSItJADX+mjkrKvl63KSNHB8TUBW/9/Zj/wTYh2XzV0=; b=aByKpzmavFG2YTixRKDtP1GPS6cZwtc4SPysuzFES+ENsOo3aXdTg5JipEnx1ZTGBu kme7FoX1nIbn1w4mZgJc78Chv3+zslmAm8vO9Ey4K7XgfuiPXwT/ljbxW4aM3fCI+P3w iXz2JXZ+ImYKQqzIAhGJbvxM5s5MPnwQA9r4i3MRm6mOQdbvGOHW4oMJJbiZ1gMnYwLV xlxY13gQse6cTW7/VckU5LQ8Qjf36m1HglMO8mVSdByD8Shiob6MokzExtoOpbW0NafS HTNJT29nhO1NXM4ZLR1/bPMQYDj4kV7G/KwoPgDVHf0C4xRq2wStr95QwlgThabt0u3B Kjyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=USX9khdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l15-20020a056402124f00b0052556e760ffsi8412711edw.74.2023.08.22.14.31.32; Tue, 22 Aug 2023 14:31:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=USX9khdc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229621AbjHVSnq (ORCPT + 99 others); Tue, 22 Aug 2023 14:43:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjHVSnq (ORCPT ); Tue, 22 Aug 2023 14:43:46 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CF290CD1; Tue, 22 Aug 2023 11:43:43 -0700 (PDT) Received: by linux.microsoft.com (Postfix, from userid 1152) id 446E12126CC3; Tue, 22 Aug 2023 11:43:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 446E12126CC3 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1692729823; bh=arqNRg4wGatPNmrOhmdLvrj5EQchfmRIhWqAHl91U0w=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=USX9khdcae7ZtgomjbVEMycgzJuC6NfFuEMyPxCgFxapYjTRfNBYOdA2EnLzaSe1s De2s6IIV6D7/w9litwf5V4341STar4r5AfY0faKCZELCijvgsfoBtDqnORhQyn+7x+ dZO+2KCaXYXAbqEQK503bglwrrytkHPdR79/3Pnk= Received: from localhost (localhost [127.0.0.1]) by linux.microsoft.com (Postfix) with ESMTP id 416C430705C5; Tue, 22 Aug 2023 11:43:43 -0700 (PDT) Date: Tue, 22 Aug 2023 11:43:43 -0700 (PDT) From: Shyam Saini To: Bart Van Assche cc: linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, op-tee@lists.trustedfirmware.org, linux-scsi@vger.kernel.org, =?ISO-8859-15?Q?Alex_Benn=E9e?= , Tomas Winkler , Ulf Hansson , Linus Walleij , Arnd Bergmann , Ilias Apalodimas , Sumit Garg , Tyler Hicks , "Srivatsa S . Bhat" , Paul Moore , Allen Pais Subject: Re: [RFC, PATCH 1/1] rpmb: add Replay Protected Memory Block (RPMB) driver In-Reply-To: <7c8945be-2549-ee79-fbdf-4870eca6f908@acm.org> Message-ID: <184a97f5-1ad1-6efc-bc7b-b41fce6f2773@linux.microsoft.com> References: <20230722014037.42647-1-shyamsaini@linux.microsoft.com> <20230722014037.42647-2-shyamsaini@linux.microsoft.com> <7c8945be-2549-ee79-fbdf-4870eca6f908@acm.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Bart, sorry for not replying earlier, as I am very new to NVMe/UFS spec and was figuring out few details about them. > On 7/21/23 18:40, Shyam Saini wrote: >> +config RPMB >> + tristate "RPMB partition interface" >> + help >> + Unified RPMB partition interface for RPMB capable devices such as >> + eMMC and UFS. Provides interface for in kernel security >> controllers to >> + access RPMB partition. >> + >> + If unsure, select N. > > Please also mention NVMe. Sure, > Please change the word "partition" into "unit" to avoid confusion with the > concept "LBA range partition". sure, in next iteration >> +static DEFINE_IDA(rpmb_ida); > > How are accesses to this IDA serialized? I will look into that. >> +/** >> + * rpmb_get_capacity() - returns the capacity of the rpmb device >> + * @rdev: rpmb device >> + * >> + * Return: >> + * * capacity of the device in units of 128K, on success >> + * * -EINVAL on wrong parameters >> + * * -EOPNOTSUPP if device doesn't support the requested operation >> + * * < 0 if the operation fails >> + */ > > Why in units of 128 KiB? I think UFS/eMMC RPMB spec suggests size of RPMB multiple of 128K and NVMe spec suggests RPMB Data Area to be multiple of 128K as well. >> +/** >> + * rpmb_dev_find_by_device() - retrieve rpmb device from the parent >> device >> + * @parent: parent device of the rpmb device >> + * @target: RPMB target/region within the physical device >> + * >> + * Return: NULL if there is no rpmb device associated with the parent >> device >> + */ > > Can an NVMe controller have multiple RPMB units? From the NVMe specification: > "The controller may support multiple RPMB targets." That we have to figure, I see NVMe device can have upto 7 RPMB targets/units > Can rpmb_dev_find_by_device() be used if multiple RPMB units are associated > with a single controller? That's not finalised yet, but we some ideas from Optee folks on the other replies. >> +/** >> + * rpmb_dev_register - register RPMB partition with the RPMB subsystem >> + * @dev: storage device of the rpmb device >> + * @target: RPMB target/region within the physical device >> + * @ops: device specific operations >> + * >> + * Return: a pointer to rpmb device >> + */ >> +struct rpmb_dev *rpmb_dev_register(struct device *dev, u8 target, >> + const struct rpmb_ops *ops) >> +{ >> + struct rpmb_dev *rdev; >> + int id; >> + int ret; >> + >> + if (!dev || !ops) >> + return ERR_PTR(-EINVAL); >> + >> + if (!ops->program_key) >> + return ERR_PTR(-EINVAL); >> + >> + if (!ops->get_capacity) >> + return ERR_PTR(-EINVAL); >> + >> + if (!ops->get_write_counter) >> + return ERR_PTR(-EINVAL); >> + >> + if (!ops->write_blocks) >> + return ERR_PTR(-EINVAL); >> + >> + if (!ops->read_blocks) >> + return ERR_PTR(-EINVAL); >> + >> + rdev = kzalloc(sizeof(*rdev), GFP_KERNEL); >> + if (!rdev) >> + return ERR_PTR(-ENOMEM); >> + >> + id = ida_simple_get(&rpmb_ida, 0, 0, GFP_KERNEL); >> + if (id < 0) { >> + ret = id; >> + goto exit; >> + } >> + >> + mutex_init(&rdev->lock); >> + rdev->ops = ops; >> + rdev->id = id; >> + rdev->target = target; >> + >> + dev_set_name(&rdev->dev, "rpmb%d", id); >> + rdev->dev.class = &rpmb_class; >> + rdev->dev.parent = dev; >> + >> + rpmb_cdev_prepare(rdev); >> + >> + ret = device_register(&rdev->dev); >> + if (ret) >> + goto exit; >> + >> + rpmb_cdev_add(rdev); >> + >> + dev_dbg(&rdev->dev, "registered device\n"); >> + >> + return rdev; >> + >> +exit: >> + if (id >= 0) >> + ida_simple_remove(&rpmb_ida, id); >> + kfree(rdev); >> + return ERR_PTR(ret); >> +} > > How is user space software supposed to map an NVMe RPMB target ID to an RPMB > device name? I am not sure, this driver aims to provide in kernel RPMB access APIs, user space support may be added later on, but i will look if the current RFC version has any implication on future user-space support. >> +MODULE_AUTHOR("Intel Corporation"); > > Shouldn't this be the name of a person instead of the name of a company? > Thanks, I will address that in next iteration. Please keep posted your reviews and feedback. Best Regards, Shyam