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 3D541C433F5 for ; Tue, 29 Mar 2022 16:59:27 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 64D7E84016; Tue, 29 Mar 2022 18:59:24 +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="mSC0PzR9"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id ADCDD83FE4; Tue, 29 Mar 2022 18:59: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 D585C83FE4 for ; Tue, 29 Mar 2022 18:59:19 +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=35zpDYgYKBoIgyi0rrmuumrk.ius0-huuzroyzy.jkt3.jk@flex--ascull.bounces.google.com Received: by mail-wm1-x34a.google.com with SMTP id r64-20020a1c2b43000000b0038b59eb1940so1169087wmr.0 for ; Tue, 29 Mar 2022 09:59:19 -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=K7pPj29EIBBjhoTibtEKK6PQI6+B/Ts55/NU/Z4bkS8=; b=mSC0PzR9LfhMKkeQPruAtPAQlRPLBNFzdSLc3qHDY00USmO6gWNigH1r5TyS8/SAoQ u/PNgyR9QMJf+W1QwqhqnmDjrHE9wzZ7IwO4OMiY/d58zC+/HRGGlgdISp1peIzRr80r HXQS+0JqSfjreFQgt36Ga+MBzZxywwKGDzUm9qWt0mFvdFxhoxgYhHKtdTvcTGvp6iGC SKqgk9jg/VYf3GwG5VX6UxoMaM3YGCGq283UlbT8A//45Ew8fcZghfwtsALcU5zq18aE 4oa5taIHBkoz0pfN07q1tvgSM7drh2CuIG5dLpJufQ+sZCKUvQ/AKySk8uObM/1hBdJH h0Ng== 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=K7pPj29EIBBjhoTibtEKK6PQI6+B/Ts55/NU/Z4bkS8=; b=nvKzZYEgfM0z4k5OxH5o8v1zX1QAj4g58Bm3h0THPk3uoEFdfT17cOA5712crjvgff x6avYOlkmTakkk+PobyFaA8iw9oIuKeSjFVuQsF9xSTD6AjcaV0kFNEEJZxmqPz8YrIr aSpQDBcOQE+RF12koXZew1GXtae7TyKB0kx5MFUQh+HHyuX2fE4tIQO5PoAsPbkDaxZX iiGtWnN38PYEr01qsJA1k+rFSQCA4SrTa08uJDfT9o3wTDy+q+u93Saw+7Idcb3IAlqJ A3Imv4WNprVHye/oLIVaqjxT9yIorDdmYlr8ZaHQPxUS7Zi7vvWtVIyfzQrMOrw5psg4 aEmw== X-Gm-Message-State: AOAM533830b8Kjlh/NkBbuG6FMBUrlBHKSydHUh6fTBUN+cQSUKP2nyZ sZiMiapFmmbye2G5iHoXk5kBcZkToxGMpa58CBkl5aF5iCVl9WXKOA4Fqs2V4AWKsY7W9+szFCH PuZ1SK7x9eFGxvrobM4jvcM1t+5vdJwyH1XmFaWIpchtNeugikHuO5/b2TJk= X-Google-Smtp-Source: ABdhPJwC5vg41+k9uDhNirn1aS/Qk1bPq1rarRTM8u8GTWzthfwoZZF4LVKxFjqeNKjvYWuyhvMJGuFEOhw= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:6000:1acf:b0:203:fe67:a8dc with SMTP id i15-20020a0560001acf00b00203fe67a8dcmr32178395wry.212.1648573159312; Tue, 29 Mar 2022 09:59:19 -0700 (PDT) Date: Tue, 29 Mar 2022 16:58:42 +0000 Message-Id: <20220329165900.1139885-1-ascull@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 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, adelva@google.com, keirf@google.com, ptosi@google.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 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: Add config for Enhanced Allocation 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() arch/sandbox/dts/test.dts | 2 +- arch/x86/cpu/baytrail/cpu.c | 2 +- drivers/ata/ahci.c | 9 +- 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/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 | 197 +++++++++++------------- drivers/spi/octeon_spi.c | 2 +- drivers/usb/host/ohci-pci.c | 2 +- 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 | 49 ++++-- test/dm/pci.c | 118 +++++++++++++- 35 files changed, 399 insertions(+), 210 deletions(-) -- 2.35.1.1021.g381101b075-goog