Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3653740pxb; Mon, 24 Jan 2022 14:31:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJyeBcwbkhXasN1Rqrh5GqVVGvVbfmFDtV3eTxODMwxf2IRu25E4zyMfpLArZcYYqXyHevFQ X-Received: by 2002:a17:902:c652:b0:14b:7488:cbfc with SMTP id s18-20020a170902c65200b0014b7488cbfcmr486525pls.5.1643063500518; Mon, 24 Jan 2022 14:31:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063500; cv=none; d=google.com; s=arc-20160816; b=sJ8fb0Kuukam24cjfLyCvWrO7T/VQfRp0j0j6IOFsSS1kGOmeMHsvrY6z/EtQVGSig ee41KWIwimkM1qRUDPIFS3avJ+T0f7nxHQGtjLQimRuAkmyofn0t9/N8HfS4coQzje11 L6bGINswfX7bSTr+xDfHQS6Y4Ux9SsAbrDRKsV2EouchDrkhNDKYtvsicHza6zfIxtp8 0HIarozuLrqqARi/9iUV5Qs6NdKVrwccc4ktfqYNeexlTypJHFS1ntKbjRc91BHc0v9U P9n56u3I+70MGqOFX8x7BvqKVLSfQiyUim1DgpTMXfaM4gBt8THHbPxzOU/XMBxP5kT3 wVlQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LRXP6rLQH7OysN7IlKauQkB6H0BIkLIP80frJ5h3aPg=; b=wEVvflqGaqMRIC6rR2/62LefdALed5n4qF1ipSehlB4t3nbGHynZnEZePziEC2eW3R 0yijGY6UNjMZ6jYeFBe+LUv66AJWWoxzMlnawQ0/ikyZuLkRzTIfR7fSSxFc1+5jlye2 GG6FMhhb5e3aEbINJgm7slW720PKjVGCTAlMYroghytQUy7JknFKXMMIpppS5T3dg4J3 tcnqOVv7UBuq0RzipN19kOT9n1vv1YgNGduf1ZYicBZEY2JAAL8tV/mQQAW/2nywvGV3 GoY1qp1/3UWKkC0UolcnySNi1DxyEV2rIbZeasTxBg/XoOBAssOJkPhS21F6MXzqbrqD 0ufw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=JZTFl0QZ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u17si5916892pfc.332.2022.01.24.14.31.28; Mon, 24 Jan 2022 14:31:40 -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=@linuxfoundation.org header.s=korg header.b=JZTFl0QZ; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1455265AbiAXW3O (ORCPT + 99 others); Mon, 24 Jan 2022 17:29:14 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:54158 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1455961AbiAXVg7 (ORCPT ); Mon, 24 Jan 2022 16:36:59 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D6691614B4; Mon, 24 Jan 2022 21:36:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 41F9FC340E4; Mon, 24 Jan 2022 21:36:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060217; bh=AaF7euI3kYHd/11AknQCQrpr2iggUpjasga3Y3juYgM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JZTFl0QZnFwybEKqgHe74ZFvBraD/WktHl0/yrQr3dkvhtbLvJ8Z7XnXnuj9OJMsW i4OmpkE0FGx7kkFHB2CMZ3u58qeOKBG0ICiVeyUXRbMDspTBtJhU1+9tWGvUGf4x8+ I1PpUSy+Izm6PHoOjLzoNrGHU/BwWT9AwpbOplOM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Pali=20Roh=C3=A1r?= , Lorenzo Pieralisi Subject: [PATCH 5.16 0877/1039] PCI: pci-bridge-emul: Fix definitions of reserved bits Date: Mon, 24 Jan 2022 19:44:26 +0100 Message-Id: <20220124184154.783323173@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Pali Rohár commit 12998087d9f48b66965b97412069c7826502cd7e upstream. Some bits in PCI_EXP registers are reserved for non-root ports. Driver pci-bridge-emul.c implements PCIe Root Port device therefore it should not allow setting reserved bits of registers. Properly define non-reserved bits for all PCI_EXP registers. Link: https://lore.kernel.org/r/20211124155944.1290-5-pali@kernel.org Fixes: 23a5fba4d941 ("PCI: Introduce PCI bridge emulated config space common logic") Signed-off-by: Pali Rohár Signed-off-by: Lorenzo Pieralisi Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pci-bridge-emul.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) --- a/drivers/pci/pci-bridge-emul.c +++ b/drivers/pci/pci-bridge-emul.c @@ -176,41 +176,55 @@ struct pci_bridge_reg_behavior pcie_cap_ [PCI_CAP_LIST_ID / 4] = { /* * Capability ID, Next Capability Pointer and - * Capabilities register are all read-only. + * bits [14:0] of Capabilities register are all read-only. + * Bit 15 of Capabilities register is reserved. */ - .ro = ~0, + .ro = GENMASK(30, 0), }, [PCI_EXP_DEVCAP / 4] = { - .ro = ~0, + /* + * Bits [31:29] and [17:16] are reserved. + * Bits [27:18] are reserved for non-upstream ports. + * Bits 28 and [14:6] are reserved for non-endpoint devices. + * Other bits are read-only. + */ + .ro = BIT(15) | GENMASK(5, 0), }, [PCI_EXP_DEVCTL / 4] = { - /* Device control register is RW */ - .rw = GENMASK(15, 0), + /* + * Device control register is RW, except bit 15 which is + * reserved for non-endpoints or non-PCIe-to-PCI/X bridges. + */ + .rw = GENMASK(14, 0), /* * Device status register has bits 6 and [3:0] W1C, [5:4] RO, - * the rest is reserved + * the rest is reserved. Also bit 6 is reserved for non-upstream + * ports. */ - .w1c = (BIT(6) | GENMASK(3, 0)) << 16, + .w1c = GENMASK(3, 0) << 16, .ro = GENMASK(5, 4) << 16, }, [PCI_EXP_LNKCAP / 4] = { - /* All bits are RO, except bit 23 which is reserved */ - .ro = lower_32_bits(~BIT(23)), + /* + * All bits are RO, except bit 23 which is reserved and + * bit 18 which is reserved for non-upstream ports. + */ + .ro = lower_32_bits(~(BIT(23) | PCI_EXP_LNKCAP_CLKPM)), }, [PCI_EXP_LNKCTL / 4] = { /* * Link control has bits [15:14], [11:3] and [1:0] RW, the - * rest is reserved. + * rest is reserved. Bit 8 is reserved for non-upstream ports. * * Link status has bits [13:0] RO, and bits [15:14] * W1C. */ - .rw = GENMASK(15, 14) | GENMASK(11, 3) | GENMASK(1, 0), + .rw = GENMASK(15, 14) | GENMASK(11, 9) | GENMASK(7, 3) | GENMASK(1, 0), .ro = GENMASK(13, 0) << 16, .w1c = GENMASK(15, 14) << 16, },