From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A7D01C433EF for ; Thu, 21 Apr 2022 16:11:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2572F83E30; Thu, 21 Apr 2022 18:11:25 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="kb7UCQwA"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD17B83DEB; Thu, 21 Apr 2022 18:11:22 +0200 (CEST) Received: from mail-wm1-x34a.google.com (mail-wm1-x34a.google.com [IPv6:2a00:1450:4864:20::34a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 0C9FD83E03 for ; Thu, 21 Apr 2022 18:11:20 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3J4JhYgYKBsoq8sA11w44w1u.s42A-r4491y898.tu3D.tu@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id i66-20020a1c3b45000000b0038eab4e0feaso2506012wma.9 for ; Thu, 21 Apr 2022 09:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=R16kipgDiBukPKMDkJaB9SU1i38Nzw4eSo0lVIVjcOA=; b=kb7UCQwAo64imxavCikE94HnG46JVPDprgM112DutvQdUgyoFJI73PvqVpz6v6348S 4eNHVEaOMM9lA7ytReV1jxSLa4aDfcOKY/3EGEWLUYkMyupV6jrdeMJP6ELc5Sqtkhoi mhyU3GAT/VgtUKpnYdkCfG+9XM+XCYo9CvE4lBaziow7opAre0FU+fEI3ULAwgxDYQAY vPLFSGgVe8tSWdv1gDlvSLO6gikq8gnrVSOfJ5pWJwu6VL5cSzLGOkGp6XepovD12miP uEOXGH0Zgukj5iyqDl/PZ1Vvz11YYqF7ssnuA7yZUT9AGEssJVyiZHL0XDvEAiCP4Iwd RwWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=R16kipgDiBukPKMDkJaB9SU1i38Nzw4eSo0lVIVjcOA=; b=S4shrB+vAJMgntS8l9+QA5WUgJOcyAnO0K3loPTHCJOZ0yENZy/j9ZvVIOx0dGIW/x 05BegwOQgTl12RJbwDyEESc/kM0fxxATYzQbhbbKkjYyojkqPhlijxJxJ35nksO9itPD t1+Jlvjm42izW/p1R01KBfncgMdko15FMRBnnqHtmSvJF2yefo1oRO03uG/mLErGqHIv XVf07uR6ZLM28DMw8uesH4Q4UVbz4MNssDm6DBfu8ruTPqcHQA3GvOBKiCbdAetqwLgO gweBEXLrfs9Hga0ZfZ8ZK9ikUCFsroLXMSThQGfKeKkPZ3O7owzLDBrimt+cZQHnMQZX pIzw== X-Gm-Message-State: AOAM531TLUz9+2wqJ5vl2J6PiQn1ZdFfvcgIZGdSOF07gveqFRwNNCl/ HlRHBgksq/Ih0K1pb+a6Rb8rCyO9amWMdJwo7CY5842amfDz7imy1a2B+9aJAeKSraboo2KB752 spc/hnIDTGG3oPnFHYrwYiGRf43+WN2D1A16j7d/AvD5NrGAWYy70V9q86Zc= X-Google-Smtp-Source: ABdhPJwLnsa72Q4lrdMKWG7bKO4//H7qwA3dhoz8CIJrGzDpSHrW2cVRoHk+Z4ZmauJ5IgS9gTsTurviEtg= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a5d:64cb:0:b0:20a:903f:5d70 with SMTP id f11-20020a5d64cb000000b0020a903f5d70mr382057wri.138.1650557479518; Thu, 21 Apr 2022 09:11:19 -0700 (PDT) Date: Thu, 21 Apr 2022 16:10:58 +0000 Message-Id: <20220421161116.1202023-1-ascull@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.36.0.rc2.479.g8af0fa9b8e-goog Subject: [PATCH v3 00/18] virtio: pci: Add and fix consistency checks From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, trini@konsulko.com, Andrew Scull Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean The virtio PCI drivers forgo a number of consistency checks, particularly around pointer validation and bounds checking. This series focuses on the modern driver to add those checks. The start of the series adds and fixes some basic bounds checks. Later patches ensure PCI addresses fall within the expected regions rather than any arbitrary address. This is acheived by introducing range parameters to a few of the dm_pci_* functions that allow the ranges to be checked. The series also adds a few new configs to allow parts of virtio and PCI to be disabled where the features may be unused and the current implementations don't have the needed consistencty checks. Changelog: v2: - Refactor dm_pci_* functions, not adding new ones - Reorder patches per request in v1 v3: - Use CI to test more targets - Move EA config patch to end for dropping if needed Andrew Scull (18): virtio: pci: Allow exclusion of legacy driver virtio: pci: Fix discovery of device config length virtio: pci: Bounds check device config access virtio: pci: Bounds check notification writes virtio: pci: Check virtio common config size virtio: pci: Check virtio capability is in bounds virtio: pci: Read entire capability into memory pci: Fix use of flags in dm_pci_map_bar() pci: Check region ranges are addressable pci: Range check address conversions test: pci: Test PCI address conversion functions pci: Map bars with offset and length pci: Match region flags using a mask pci: Update dm_pci_bus_to_virt() parameters pci: Add mask parameter to dm_pci_map_bar() virtio: pci: Check virtio configs are mapped virtio: pci: Make use of dm_pci_map_bar() pci: Add config for Enhanced Allocation arch/sandbox/dts/test.dts | 2 +- arch/x86/cpu/baytrail/cpu.c | 2 +- drivers/ata/ahci.c | 9 +- drivers/ata/sata_sil.c | 6 +- drivers/bios_emulator/atibios.c | 4 +- drivers/gpio/octeon_gpio.c | 2 +- drivers/i2c/designware_i2c_pci.c | 3 +- drivers/i2c/intel_i2c.c | 2 +- drivers/i2c/octeon_i2c.c | 2 +- drivers/mmc/octeontx_hsmmc.c | 2 +- drivers/mmc/pci_mmc.c | 2 +- drivers/mtd/nand/raw/octeontx_bch.c | 6 +- drivers/mtd/nand/raw/octeontx_nand.c | 2 +- drivers/net/bnxt/bnxt.c | 9 +- drivers/net/e1000.c | 4 +- drivers/net/fsl_enetc.c | 2 +- drivers/net/fsl_enetc_mdio.c | 2 +- drivers/net/mscc_eswitch/felix_switch.c | 4 +- drivers/net/octeontx/bgx.c | 2 +- drivers/net/octeontx/nic_main.c | 2 +- drivers/net/octeontx/nicvf_main.c | 2 +- drivers/net/octeontx/smi.c | 2 +- drivers/net/octeontx2/cgx.c | 2 +- drivers/net/octeontx2/rvu_af.c | 2 +- drivers/net/octeontx2/rvu_pf.c | 3 +- drivers/net/pch_gbe.c | 2 +- drivers/nvme/nvme_pci.c | 4 +- drivers/pci/Kconfig | 7 + drivers/pci/pci-uclass.c | 185 +++++++++++------------- drivers/spi/octeon_spi.c | 2 +- drivers/usb/host/ehci-pci.c | 3 +- drivers/usb/host/ohci-pci.c | 2 +- drivers/usb/host/xhci-pci.c | 3 +- drivers/virtio/Kconfig | 9 ++ drivers/virtio/Makefile | 3 +- drivers/virtio/virtio_pci_legacy.c | 3 +- drivers/virtio/virtio_pci_modern.c | 143 ++++++++++++------ include/pci.h | 46 ++++-- test/dm/pci.c | 118 ++++++++++++++- 39 files changed, 401 insertions(+), 209 deletions(-) -- 2.36.0.rc2.479.g8af0fa9b8e-goog