Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp2026452rdb; Tue, 3 Oct 2023 08:11:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGyyVYFJ0Xv1HYotSSRk3R4N6QQaoCbKPa/b0G1A020ekrRA6GklOpenzp/DTp01aOheu30 X-Received: by 2002:a05:6a21:338c:b0:137:3c67:85d7 with SMTP id yy12-20020a056a21338c00b001373c6785d7mr15762365pzb.16.1696345871401; Tue, 03 Oct 2023 08:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696345871; cv=none; d=google.com; s=arc-20160816; b=vq+CfgCLrhdqW0xrA5dWk5nfRo55vJ5Umg0tbjA5tcEGycKVP775SpQ6GRhAeChT02 FcSWewFWbAV8TfuSsEGbtIq0l03kvVBwSJqJeG0BxEJ6uY+ka5yM1ikOP2HrTHUN4C4D ELAIu5/xJYtOSBNGPYKqeGY9V6VFq8PTmFDz25PAx/p2ibiIwiuv1KBYgbIKptqB0J6D BAJEhvoLbcIkfVyFeH/lxdByCaPCqTtEmyw3BQXudDQqVV7lZYGaeqCiuK3cH01u+xbh w3tFieYZF03lAbRFppVWLOquHCEFeCVa1FBo640sFEIqJAqCZf5O+F6byyng0bcnbija T+0A== 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=EnbIsjDSYdRjgNyyDkBggSwMDUj/dmVbz6bK3DQcBgM=; fh=VytaWnrtIe6rQzSTidyaXKVP21CYVB05Erb1vcNmZ/4=; b=LDxd6FXwzvOetcGg/kYboUHr2LbTdw7V/n7+ewfvQ84PFMPazd9Ld3b2lGR3y/JLhD NsUy+3YwZbViFXNUpnZ0B8Exw7Qrn7smClOkZ4FgQuwkTUg12L3vnDMkorPV4wdxp2RD txS7COeD4FGs1sWDFE+9PKHivM2nYI2K9JABrNFKpMjJqc3zNih7KbGa7htjR6jxB3lU cJWaOhQIT9QCOgd+ILjzKhpL+HI+1tr3chTC6aNHgnXP/IGMujR+cYQ6sgf0htHrTBCw XX2mwjGqEiUmsb7czZe2stjQ09qg1D68fKMwbnPdnzsHegNib3TKdFgrjx5U9SsgHdsH qlTg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id cq14-20020a056a00330e00b0068e45c6ca3fsi1667784pfb.93.2023.10.03.08.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 08:11:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id 13F628080D6D; Tue, 3 Oct 2023 08:10:59 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240243AbjJCPKt (ORCPT + 99 others); Tue, 3 Oct 2023 11:10:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240261AbjJCPKt (ORCPT ); Tue, 3 Oct 2023 11:10:49 -0400 Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5421BF; Tue, 3 Oct 2023 08:10:45 -0700 (PDT) Received: from lhrpeml500005.china.huawei.com (unknown [172.18.147.201]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4S0LqG2vVZz67G90; Tue, 3 Oct 2023 23:10:34 +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 16:10:42 +0100 Date: Tue, 3 Oct 2023 16:10:41 +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 10/12] PCI/CMA: Reauthenticate devices on reset and resume Message-ID: <20231003161041.0000762d@Huawei.com> In-Reply-To: References: 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 groat.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 (groat.vger.email [0.0.0.0]); Tue, 03 Oct 2023 08:10:59 -0700 (PDT) On Thu, 28 Sep 2023 19:32:40 +0200 Lukas Wunner wrote: > CMA-SPDM state is lost when a device undergoes a Conventional Reset. > (But not a Function Level Reset, PCIe r6.1 sec 6.6.2.) A D3cold to D0 > transition implies a Conventional Reset (PCIe r6.1 sec 5.8). > > Thus, reauthenticate devices on resume from D3cold and on recovery from > a Secondary Bus Reset or DPC-induced Hot Reset. > > The requirement to reauthenticate devices on resume from system sleep > (and in the future reestablish IDE encryption) is the reason why SPDM > needs to be in-kernel: During ->resume_noirq, which is the first phase > after system sleep, the PCI core walks down the hierarchy, puts each > device in D0, restores its config space and invokes the driver's > ->resume_noirq callback. The driver is afforded the right to access the > device already during this phase. > > To retain this usage model in the face of authentication and encryption, > CMA-SPDM reauthentication and IDE reestablishment must happen during the > ->resume_noirq phase, before the driver's first access to the device. > The driver is thus afforded seamless authenticated and encrypted access > until the last moment before suspend and from the first moment after > resume. > > During the ->resume_noirq phase, device interrupts are not yet enabled. > It is thus impossible to defer CMA-SPDM reauthentication to a user space > component on an attached disk or on the network, making an in-kernel > SPDM implementation mandatory. > > The same catch-22 exists on recovery from a Conventional Reset: A user > space SPDM implementation might live on a device which underwent reset, > rendering its execution impossible. > > Signed-off-by: Lukas Wunner > --- > drivers/pci/cma.c | 10 ++++++++++ > drivers/pci/pci-driver.c | 1 + > drivers/pci/pci.c | 12 ++++++++++-- > drivers/pci/pci.h | 5 +++++ > drivers/pci/pcie/err.c | 3 +++ > include/linux/pci.h | 1 + > 6 files changed, 30 insertions(+), 2 deletions(-) > > diff --git a/drivers/pci/cma.c b/drivers/pci/cma.c > index 012190c54ab6..89d23fdc37ec 100644 > --- a/drivers/pci/cma.c > +++ b/drivers/pci/cma.c > @@ -71,6 +71,16 @@ void pci_cma_init(struct pci_dev *pdev) > } > > rc = spdm_authenticate(pdev->spdm_state); > + if (rc != -EPROTONOSUPPORT) > + pdev->cma_capable = true; This is the blob that I think wants pulling forwards to earlier patch so that rc = isn't left hanging. > +} > + > +int pci_cma_reauthenticate(struct pci_dev *pdev) > +{ > + if (!pdev->cma_capable) > + return -ENOTTY; > + > + return spdm_authenticate(pdev->spdm_state); If authenticate failed why did we leave spdm_state around? That feels like a corner case in the earlier patch that needs documentation. I can see maybe certs not provisioned yet would be a valid reason or an intermittent fault (solved by reset) but in those cases we'd want to try again on reset anyway... > } > > void pci_cma_destroy(struct pci_dev *pdev) > diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c > index a79c110c7e51..b5d47eefe8df 100644 > --- a/drivers/pci/pci-driver.c > +++ b/drivers/pci/pci-driver.c > @@ -568,6 +568,7 @@ static void pci_pm_default_resume_early(struct pci_dev *pci_dev) > pci_pm_power_up_and_verify_state(pci_dev); > pci_restore_state(pci_dev); > pci_pme_restore(pci_dev); > + pci_cma_reauthenticate(pci_dev); > } > > static void pci_pm_bridge_power_up_actions(struct pci_dev *pci_dev) > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > index 59c01d68c6d5..0f36e6082579 100644 > --- a/drivers/pci/pci.c > +++ b/drivers/pci/pci.c > @@ -5248,8 +5248,16 @@ static int pci_reset_bus_function(struct pci_dev *dev, bool probe) > > rc = pci_dev_reset_slot_function(dev, probe); > if (rc != -ENOTTY) > - return rc; > - return pci_parent_bus_reset(dev, probe); > + goto done; > + > + rc = pci_parent_bus_reset(dev, probe); > + > +done: > + /* CMA-SPDM state is lost upon a Conventional Reset */ > + if (!probe) > + pci_cma_reauthenticate(dev); > + > + return rc; > } > > void pci_dev_lock(struct pci_dev *dev) > diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h > index 6c4755a2c91c..71092ccf4fbd 100644 > --- a/drivers/pci/pci.h > +++ b/drivers/pci/pci.h > @@ -325,11 +325,16 @@ static inline void pci_doe_disconnected(struct pci_dev *pdev) { } > #ifdef CONFIG_PCI_CMA > void pci_cma_init(struct pci_dev *pdev); > void pci_cma_destroy(struct pci_dev *pdev); > +int pci_cma_reauthenticate(struct pci_dev *pdev); > struct x509_certificate; > int pci_cma_validate(struct device *dev, struct x509_certificate *leaf_cert); > #else > static inline void pci_cma_init(struct pci_dev *pdev) { } > static inline void pci_cma_destroy(struct pci_dev *pdev) { } > +static inline int pci_cma_reauthenticate(struct pci_dev *pdev) > +{ > + return -ENOTTY; > +} > #endif > > /** > diff --git a/drivers/pci/pcie/err.c b/drivers/pci/pcie/err.c > index 59c90d04a609..4783bd907b54 100644 > --- a/drivers/pci/pcie/err.c > +++ b/drivers/pci/pcie/err.c > @@ -122,6 +122,9 @@ static int report_slot_reset(struct pci_dev *dev, void *data) > pci_ers_result_t vote, *result = data; > const struct pci_error_handlers *err_handler; > > + /* CMA-SPDM state is lost upon a Conventional Reset */ > + pci_cma_reauthenticate(dev); > + > device_lock(&dev->dev); > pdrv = dev->driver; > if (!pdrv || > diff --git a/include/linux/pci.h b/include/linux/pci.h > index 0c0123317df6..2bc11d8b567e 100644 > --- a/include/linux/pci.h > +++ b/include/linux/pci.h > @@ -519,6 +519,7 @@ struct pci_dev { > #endif > #ifdef CONFIG_PCI_CMA > struct spdm_state *spdm_state; /* Security Protocol and Data Model */ > + unsigned int cma_capable:1; /* Authentication supported */ Also this should I think move to the earlier patch where we know if it is supported even though we don't use it until here. > #endif > u16 acs_cap; /* ACS Capability offset */ > phys_addr_t rom; /* Physical address if not from BAR */