Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2010095rdb; Tue, 3 Oct 2023 07:48:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHMT6K/5rBCB5CKvx9dMk40jB9548CXy4kdyLeiD84S/f5a31hyPELDp4ESxplCaF57b8X1 X-Received: by 2002:a05:6a20:8427:b0:166:6582:a7d5 with SMTP id c39-20020a056a20842700b001666582a7d5mr1562987pzd.3.1696344483199; Tue, 03 Oct 2023 07:48:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696344483; cv=none; d=google.com; s=arc-20160816; b=nDlbUWg8hKMp+MWJcxywSnok7B18sOUTmG7SRC3w4MfHkxoigmbyapnPo4+Bh0lHn9 MiWUkUf443upMfrcypbVHlt3hlEJqKzqKfCXDK0vPe3bz4mCeL90aGLLu/MYmZpnpfW1 /1NVjejcClQwTytD/j6+E9MVUTJ8NDUJJEz4N9SmA/lhVUWhKUQF5bJ41LuPxHe/YGOY c7RaeoOQ5UnTruP+BoEQ4w4Cr4nG6weGcgSPJypIoK5aXWe3FL/U2XTKs6mmsqDzP979 Utuv8wrtjnWWNmt+xVAm6s5TqoVX7X509sGnrH658TnD3zjpIHzJvf4nHyxiDrTOATBa sLgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=h/cx36RdBy6F4mVRLCHFlyosu6qwDbmaB4k7UqMN1SM=; fh=VytaWnrtIe6rQzSTidyaXKVP21CYVB05Erb1vcNmZ/4=; b=fFDCAr/+2zNGeBpjumObWtUAQgS0AXVKWsIBwDlvfTUByyVVLzD7NBqaUJnUpiChKi XLM1MCTjLjb4ILyDGumMPTRR8C1vZErvGFgIUZsALcCGmcLsRz7KGA7DObn88AaqDDoj KGH0x09OD9tAiW2jWCv2tBm+lkUJtzaSSB+rdBeVmNLmCsCIWIbbSFJ/k75vpL4TSc+v HFMIvO3TCHcrOeKR0aHgal6fSNVWWvPqhi8y7l+IWdMPMsu0ZYSmrVHh3El398ewun6/ 3L3/Tp6LnrQf/BdokacrLi03II15UlvBmoU1YckNFjpUSzeeB5GpFNc/4YCeZGp54kPe snGw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id c22-20020a056a000ad600b0069347c30c78si1652110pfl.230.2023.10.03.07.48.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 07:48:03 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id C2C4F8135C7E; Tue, 3 Oct 2023 07:47:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240149AbjJCOsA (ORCPT + 99 others); Tue, 3 Oct 2023 10:48:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbjJCOr7 (ORCPT ); Tue, 3 Oct 2023 10:47:59 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0BCDCAC; Tue, 3 Oct 2023 07:47:56 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.226]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4S0LG135ykz6HJbr; Tue, 3 Oct 2023 22:45:13 +0800 (CST) Received: from localhost (10.202.227.76) by lhrpeml500005.china.huawei.com (7.191.163.240) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 3 Oct 2023 15:47:53 +0100 Date: Tue, 3 Oct 2023 15:47:51 +0100 From: Jonathan Cameron To: Lukas Wunner CC: Bjorn Helgaas , David Howells , David Woodhouse , Herbert Xu , "David S. Miller" , Alex Williamson , , , , , , , , David Box , Dan Williams , Dave Jiang , "Li, Ming" , Zhi Wang , Alistair Francis , Wilfred Mallawa , Alexey Kardashevskiy , Tom Lendacky , Sean Christopherson , Alexander Graf Subject: Re: [PATCH 08/12] PCI/CMA: Authenticate devices on enumeration Message-ID: <20231003154751.00004de7@Huawei.com> In-Reply-To: <7721bfa3b4f8a99a111f7808ad8890c3c13df56d.1695921657.git.lukas@wunner.de> References: <7721bfa3b4f8a99a111f7808ad8890c3c13df56d.1695921657.git.lukas@wunner.de> Organization: Huawei Technologies Research and Development (UK) Ltd. X-Mailer: Claws Mail 4.1.0 (GTK 3.24.33; x86_64-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.227.76] X-ClientProxiedBy: lhrpeml100001.china.huawei.com (7.191.160.183) To lhrpeml500005.china.huawei.com (7.191.163.240) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 03 Oct 2023 07:47:59 -0700 (PDT) On Thu, 28 Sep 2023 19:32:38 +0200 Lukas Wunner wrote: > From: Jonathan Cameron > > Component Measurement and Authentication (CMA, PCIe r6.1 sec 6.31) > allows for measurement and authentication of PCIe devices. It is > based on the Security Protocol and Data Model specification (SPDM, > https://www.dmtf.org/dsp/DSP0274). > > CMA-SPDM in turn forms the basis for Integrity and Data Encryption > (IDE, PCIe r6.1 sec 6.33) because the key material used by IDE is > exchanged over a CMA-SPDM session. > > As a first step, authenticate CMA-capable devices on enumeration. > A subsequent commit will expose the result in sysfs. > > When allocating SPDM session state with spdm_create(), the maximum SPDM > message length needs to be passed. Make the PCI_DOE_MAX_LENGTH macro > public and calculate the maximum payload length from it. > > Credits: Jonathan wrote a proof-of-concept of this CMA implementation. > Lukas reworked it for upstream. Wilfred contributed fixes for issues > discovered during testing. > > Signed-off-by: Jonathan Cameron > Signed-off-by: Wilfred Mallawa > Signed-off-by: Lukas Wunner Hi Lukas, A few things inline. Biggest of which is making this one build warning free by pulling forward the cma_capable flag from patch 10. > > diff --git a/drivers/pci/cma.c b/drivers/pci/cma.c > new file mode 100644 > index 000000000000..06e5846325e3 > --- /dev/null > +++ b/drivers/pci/cma.c > +void pci_cma_init(struct pci_dev *pdev) > +{ > + struct pci_doe_mb *doe; > + int rc; > + > + if (!pci_cma_keyring) { > + return; > + } > + > + if (!pci_is_pcie(pdev)) > + return; > + > + doe = pci_find_doe_mailbox(pdev, PCI_VENDOR_ID_PCI_SIG, > + PCI_DOE_PROTOCOL_CMA); > + if (!doe) > + return; > + > + pdev->spdm_state = spdm_create(&pdev->dev, pci_doe_transport, doe, > + PCI_DOE_MAX_PAYLOAD, pci_cma_keyring); > + if (!pdev->spdm_state) { > + return; > + } Brackets not needed. > + > + rc = spdm_authenticate(pdev->spdm_state); Hanging rc? There is a blob in patch 10 that uses it, but odd to keep it around in meantime. Perhaps just add the flag in this patch and set it even though no one cares about it yet. > +} > + > +void pci_cma_destroy(struct pci_dev *pdev) > +{ > + if (pdev->spdm_state) > + spdm_destroy(pdev->spdm_state); > +} > + > +__init static int pci_cma_keyring_init(void) > +{ > + pci_cma_keyring = keyring_alloc(".cma", KUIDT_INIT(0), KGIDT_INIT(0), > + current_cred(), > + (KEY_POS_ALL & ~KEY_POS_SETATTR) | > + KEY_USR_VIEW | KEY_USR_READ | > + KEY_USR_WRITE | KEY_USR_SEARCH, > + KEY_ALLOC_NOT_IN_QUOTA | > + KEY_ALLOC_SET_KEEP, NULL, NULL); > + if (IS_ERR(pci_cma_keyring)) { > + pr_err("Could not allocate keyring\n"); > + return PTR_ERR(pci_cma_keyring); > + } > + > + return 0; > +} > +arch_initcall(pci_cma_keyring_init);