Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp625477pxb; Tue, 3 Nov 2020 08:18:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJzHpBi10DMcZ3ogoUgdobJJa1bVcn2oD5tt9R2Al98WWrDan5wTo9bf+SlGLGjrGIvOITox X-Received: by 2002:aa7:cac2:: with SMTP id l2mr22873424edt.141.1604420307405; Tue, 03 Nov 2020 08:18:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604420307; cv=none; d=google.com; s=arc-20160816; b=Uu9Ky7yB+OrTFCCDeJTM2EmVh1vNfvXsEjlxJIhmigl3NOY1c7WrbN2sCJqZlugCQW Sybb/Kso4Xlw/LqpazwKVET+DEZsHi34sPHLqzvzoQmt75YziMWjsb2xRnqqn95PJG+I LoYLEgdyokJKx72AuPeorZn4o2EEke7d7dIvpSlaYQJn7Uz3PW/YDFUN6f6YjfLy+mqK Jam8DyfSo3lPcPNrfWMSQc2Q7KLplfuE2W6A1ydMcygr6Uao87oNdCTAJj6nhPVdp0wN v+uBwz0G3hFuyB8V1kmxpEZSE0hhXua6qYUVEFpaLaP3tlS6ZWoQ2nkQcRhyFS0Ak1St aJPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nmEKn5Zrmqx5dbhUPcLYxuV5y8DB52aplLnItU43Q1c=; b=wcTds88RJYtjEIATw83WQqObmSO0GRJzktRcwQMEg+rqg/Ob1k5AfNUM96igmZ3Nf3 C2ryUQ48pRzXvpfjYfItZBHhv8TQpyOlQocAlb4wwapsk9845Nd5dxG6nMOQMzPwwOQi CY3U6b/N5WJ5WIcNvKcGBJ8FUPSVVemVBq2qhQGaussOOmoWci+7ydgB8wNYlBMIj6m+ /z3clc7ZgP6EmEVkLY9gjGdL8qAuta1Es51DVfK5F+H9xSSAxNtuFag1Z1UAMBQpW/jR 8rfVDpOO8zSsXrHzGAAiiTNe2F4Iwg3eSBMvKxpfek6o9oHHrTDQyiKv7m9lFZycBHZ1 kXUQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=EK3H8Ewq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gj23si13329067ejb.391.2020.11.03.08.18.04; Tue, 03 Nov 2020 08:18:27 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@eclypsium.com header.s=google header.b=EK3H8Ewq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=eclypsium.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728234AbgKCQPq (ORCPT + 99 others); Tue, 3 Nov 2020 11:15:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35758 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728184AbgKCQPq (ORCPT ); Tue, 3 Nov 2020 11:15:46 -0500 Received: from mail-qv1-xf43.google.com (mail-qv1-xf43.google.com [IPv6:2607:f8b0:4864:20::f43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BEC09C0613D1 for ; Tue, 3 Nov 2020 08:15:44 -0800 (PST) Received: by mail-qv1-xf43.google.com with SMTP id t20so7979338qvv.8 for ; Tue, 03 Nov 2020 08:15:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclypsium.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nmEKn5Zrmqx5dbhUPcLYxuV5y8DB52aplLnItU43Q1c=; b=EK3H8Ewqk5l+B96a+MyscWTns6s6omz2s8Us8jygAnTG9bbwo2vqEuGsPI2vVM39t2 cv/ismoz3SMJydKNJ2YS+XJXeOAXs/WG2tkQgEP7nPRfoltXBI8EYApDuN01LbjZeCSu FXJGbOhjcKmbfs6fdkcItuVCYZfbp5mBWgrSIjRmg4N/RrFqJK1u2GFgGI6tzCm1yPe5 UDtq2AjHkQ3bSrfmNPuRSGF2B0GcE1shCXDicfBsdd320iew0XMVreXfq7DjXigFDUm4 Eejnf29gbmITQcFe3U7ZEJr3mMwoUGsmmMe4fr8o0rB5a9ut6vTl+gqzaO7Ys3xWeMNi cm0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nmEKn5Zrmqx5dbhUPcLYxuV5y8DB52aplLnItU43Q1c=; b=DgHSW085iH9J0Qa1gYVcm6C4xRFOZPsNdkQQBAQPOFkcG/0aCFldKtlUaYKfHImxkk E0lCNT6TZ42Hfk8P3KyYlETOFjwCqoi9GrnifSmUM3sgc0L1/ggi352KwwYIkZPYtkwF xuyo5C5oKDHIj3dbQ6I8X/blANwByhQ4A6sAordJMWpLyhQwEhbfkuBOErkludo+muf9 7VugVusQ3tuI/sTIB8G9F29Gzyf6dCWIi2j3ezpj8yPYvQlDbH96a5vCOgfCrYU4TzVW 8RkbCWqzQmFv/ejgpp18ltMGubCs1dahpzjcrMZFwT45amzOepoyZ8pGIG8xxj5gXB8v lAZw== X-Gm-Message-State: AOAM533mJ4FkIX9bkCL8HlHOkLzZ4kfKtCZ0OkGDQG9UazykTfsUIbrp SMMxirbzQPPWiLaw1czByGuVJo7YmbJmRyMSNGenu2dc/FRApQ== X-Received: by 2002:ad4:5808:: with SMTP id dd8mr27209389qvb.58.1604420143732; Tue, 03 Nov 2020 08:15:43 -0800 (PST) MIME-Version: 1.0 References: <20201028214359.384918-1-daniel.gutson@eclypsium.com> <20201029054110.GA3039992@kroah.com> <20201029191505.GC986195@kroah.com> <20201103160842.GA4153227@kroah.com> In-Reply-To: <20201103160842.GA4153227@kroah.com> From: Daniel Gutson Date: Tue, 3 Nov 2020 13:15:32 -0300 Message-ID: Subject: Re: [PATCH] mtd: spi-nor: intel-spi: Split intel-spi reading from writing To: Greg Kroah-Hartman Cc: Derek Kiernan , Tudor Ambarus , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Mika Westerberg , Arnd Bergmann , Mauro Carvalho Chehab , linux-kernel , Richard Hughes , Alex Bazhaniuk , linux-mtd Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Nov 3, 2020 at 1:07 PM Greg Kroah-Hartman wrote: > > On Tue, Nov 03, 2020 at 12:18:01PM -0300, Daniel Gutson wrote: > > On Thu, Oct 29, 2020 at 4:14 PM Greg Kroah-Hartman > > wrote: > > > > > > On Thu, Oct 29, 2020 at 12:39:08PM -0300, Daniel Gutson wrote: > > > > On Thu, Oct 29, 2020 at 2:40 AM Greg Kroah-Hartman > > > > wrote: > > > > > > > > > > On Wed, Oct 28, 2020 at 06:43:59PM -0300, Daniel Gutson wrote: > > > > > > This patch separates the writing part of the intel-spi drivers > > > > > > so the 'dangerous' part can be set/unset independently. > > > > > > This way, the kernel can be configured to include the reading > > > > > > parts of the driver which can be used without > > > > > > the dangerous write operations that can turn the system > > > > > > unbootable. > > > > > > > > > > > > Signed-off-by: Daniel Gutson > > > > > > --- > > > > > > drivers/mtd/spi-nor/controllers/Kconfig | 39 ++++++++++++--------- > > > > > > drivers/mtd/spi-nor/controllers/intel-spi.c | 12 +++++-- > > > > > > 2 files changed, 33 insertions(+), 18 deletions(-) > > > > > > > > > > > > diff --git a/drivers/mtd/spi-nor/controllers/Kconfig b/drivers/mtd/spi-nor/controllers/Kconfig > > > > > > index 5c0e0ec2e6d1..491c755fea49 100644 > > > > > > --- a/drivers/mtd/spi-nor/controllers/Kconfig > > > > > > +++ b/drivers/mtd/spi-nor/controllers/Kconfig > > > > > > @@ -31,34 +31,41 @@ config SPI_INTEL_SPI > > > > > > tristate > > > > > > > > > > > > config SPI_INTEL_SPI_PCI > > > > > > - tristate "Intel PCH/PCU SPI flash PCI driver (DANGEROUS)" > > > > > > + tristate "Intel PCH/PCU SPI flash PCI driver" > > > > > > depends on X86 && PCI > > > > > > select SPI_INTEL_SPI > > > > > > help > > > > > > - This enables PCI support for the Intel PCH/PCU SPI controller in > > > > > > - master mode. This controller is present in modern Intel hardware > > > > > > - and is used to hold BIOS and other persistent settings. Using > > > > > > - this driver it is possible to upgrade BIOS directly from Linux. > > > > > > - > > > > > > - Say N here unless you know what you are doing. Overwriting the > > > > > > - SPI flash may render the system unbootable. > > > > > > + This enables read only PCI support for the Intel PCH/PCU SPI > > > > > > + controller in master mode. This controller is present in modern > > > > > > + Intel hardware and is used to hold BIOS and other persistent settings. > > > > > > + Using this driver it is possible to read the SPI chip directly > > > > > > + from Linux. > > > > > > > > > > > > To compile this driver as a module, choose M here: the module > > > > > > will be called intel-spi-pci. > > > > > > > > > > > > config SPI_INTEL_SPI_PLATFORM > > > > > > - tristate "Intel PCH/PCU SPI flash platform driver (DANGEROUS)" > > > > > > + tristate "Intel PCH/PCU SPI flash platform driver" > > > > > > depends on X86 > > > > > > select SPI_INTEL_SPI > > > > > > help > > > > > > - This enables platform support for the Intel PCH/PCU SPI > > > > > > + This enables read only platform support for the Intel PCH/PCU SPI > > > > > > controller in master mode. This controller is present in modern > > > > > > - Intel hardware and is used to hold BIOS and other persistent > > > > > > - settings. Using this driver it is possible to upgrade BIOS > > > > > > - directly from Linux. > > > > > > + Intel hardware and is used to hold BIOS and other persistent settings. > > > > > > + Using this driver it is possible to read the SPI chip directly > > > > > > + from Linux. > > > > > > + > > > > > > + To compile this driver as a module, choose M here: the module > > > > > > + will be called intel-spi-pci. > > > > > > + > > > > > > +config SPI_INTEL_SPI_WRITE > > > > > > + bool "Intel PCH/PCU SPI flash drivers write operations (DANGEROUS)" > > > > > > + depends on SPI_INTEL_SPI_PCI || SPI_INTEL_SPI_PLATFORM > > > > > > + help > > > > > > + This enables full read/write support for the Intel PCH/PCU SPI > > > > > > + controller. > > > > > > + Using this option it may be possible to upgrade BIOS directly > > > > > > + from Linux. > > > > > > > > > > > > Say N here unless you know what you are doing. Overwriting the > > > > > > SPI flash may render the system unbootable. > > > > > > - > > > > > > - To compile this driver as a module, choose M here: the module > > > > > > - will be called intel-spi-platform. > > > > > > diff --git a/drivers/mtd/spi-nor/controllers/intel-spi.c b/drivers/mtd/spi-nor/controllers/intel-spi.c > > > > > > index b54a56a68100..8d8053395c3d 100644 > > > > > > --- a/drivers/mtd/spi-nor/controllers/intel-spi.c > > > > > > +++ b/drivers/mtd/spi-nor/controllers/intel-spi.c > > > > > > @@ -266,6 +266,7 @@ static int intel_spi_read_block(struct intel_spi *ispi, void *buf, size_t size) > > > > > > return 0; > > > > > > } > > > > > > > > > > > > +#ifdef CONFIG_SPI_INTEL_SPI_WRITE > > > > > > > > > > > > > > > > > > > > Please do not add #ifdef to .c files, that's not the proper kernel > > > > > coding style at all, and just makes maintaining this file much much > > > > > harder over time. > > > > > > > > > > Split things out into two different files if you really need to do this. > > > > > > > > What about the static functions that I'll need to turn non-static and > > > > in a header file? > > > > I mean, the functions that the functions in the new file will have to call. > > > > Should I do that, turn static functions into non-static and declared > > > > in a header file? > > > > > > No idea, but again, no #ifdefs in .c files like this, that is not the > > > proper kernel coding style as it is not maintainable for the lifespan > > > that we have to maintain code. > > > > Is it acceptable to leave static functions unused and let the optimizer > > remove them as DCE? > > You will get build warnings if you do that, right? I don't know why I didn't get any unused function warning, but OK. I'm using a decently recent gcc. > > You have thousands of examples of how to do this correct, it shouldn't > be that tough :) The job is not that tough, you are to accept changes :) > > thanks, > > greg k-h -- Daniel Gutson Engineering Director Eclypsium, Inc. Below The Surface: Get the latest threat research and insights on firmware and supply chain threats from the research team at Eclypsium. https://eclypsium.com/research/#threatreport