From patchwork Fri Nov 9 23:16:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Venkatesh Srinivas X-Patchwork-Id: 10676679 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7228E13AD for ; Fri, 9 Nov 2018 23:16:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6234D2F174 for ; Fri, 9 Nov 2018 23:16:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 50D942F187; Fri, 9 Nov 2018 23:16:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5A852F174 for ; Fri, 9 Nov 2018 23:16:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728287AbeKJI7f (ORCPT ); Sat, 10 Nov 2018 03:59:35 -0500 Received: from mail-io1-f74.google.com ([209.85.166.74]:47931 "EHLO mail-io1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727023AbeKJI7f (ORCPT ); Sat, 10 Nov 2018 03:59:35 -0500 Received: by mail-io1-f74.google.com with SMTP id y8-v6so3701811ioc.14 for ; Fri, 09 Nov 2018 15:16:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=r++WJn0S1mqv9UEDqLjf2DUWBxQbwtMMuy7+AZGsJ00=; b=e7srPGzl/HzGSO3vEW+66Aoez4vMmst8hRnIOrVvzrlEW7MmexNtNRJvSubNFX988e 8frNneTqtvIxGBzWqFs1iAzfvRwX3Kfa60PA7O58KcRyDRgwS1jhszkfA60ZwiaPzfWh rOWqW0aHFwLobFswjKYWmauxI3ikX+sDVNuDGWx+IQHJ6ZSdhNLZmfbfu4EsvVl9CIKJ CM7dECzLaG6Cxd1NXsL2nXZldKMvyJbde0hb/+HW5e09m6kOBtACkovvAETP7gd3o7fL zmP6rJbcuuZl3m4Nh9vmrSyjbgEHvnXOgXXgbvsgd+h7ctaJRl4NHVKRUJC9G0B/YTJk f7Ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=r++WJn0S1mqv9UEDqLjf2DUWBxQbwtMMuy7+AZGsJ00=; b=kfWKuj23Hld0zjsPBTrbGGQOqJZZ0JVz35EClYfvr9gSmYAqWmmhboTkJ+uK4l9lrA 9m27zXKYpEmbbK4MP6BI9azZhiN94+f8/FPfd51a39iwQA69FrQYBDigcR5EOiB1WxNy XkXsaPGUvbhmk/Z2/S3ZiRFKBmp8jdnv7BqKUSJbuyvRM/kX4yoVPCJLKHOhqFyLAc/w TGD556dZW6PQm/PQqMp+pt7z657olz43lcq09X5k9Zu7TrRGoFTVRDHhkUb3qTSt/u4c Qfdk+AiFIpIDvo4jP9Q8p/sig4F737w+Tku3jS9aloLc//DOltdUtkA2xS7Yk93D3TSV 3b+g== X-Gm-Message-State: AGRZ1gKaWP/8TI1DWDhpSNIPFtwm5vI0qO3Aj3ml6961Dmh6fHfanMET RyRf282luT6XwJnyd1anoL2FUQ2GxOYWSnKZ X-Google-Smtp-Source: AJdET5esLC3Y8c/na9BdUUDrVCe3fGEyP4YrZamG35ORa6XVbpO3nJPLt01Z1jiEcwqt56tKMbuAOGdv/zlOX82O X-Received: by 2002:a24:8785:: with SMTP id f127-v6mr3539274ite.6.1541805409661; Fri, 09 Nov 2018 15:16:49 -0800 (PST) Date: Fri, 9 Nov 2018 18:16:37 -0500 Message-Id: <20181109231637.231582-1-venkateshs@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog Subject: [PATCH] uio/uio_pci_generic: Disable bus-mastering on release From: Venkatesh Srinivas To: mst@redhat.com Cc: kvm@vger.kernel.org, venkateshs@google.com, vsrinivas@ops101.org, Bjorn Helgaas , Catherine Sullivan Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Userspace code using uio_pci_generic may enable bus-mastering by directly manipulating a PCI device's command register. If a userspace program enables bus-mastering but exits/crashes uncleanly, bus- mastering will still be enabled and stale DMA addresses may be programmed and live in the device. Disable bus-mastering unconditionally on last close of a UIO PCI fd to avoid this. If the device did not have bus-mastering enabled, pci_clear_master() is a no-op. Signed-off-by: Venkatesh Srinivas Reviewed-by: Bjorn Helgaas Reviewed-by: Catherine Sullivan --- drivers/uio/uio_pci_generic.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/uio/uio_pci_generic.c b/drivers/uio/uio_pci_generic.c index 8773e373ffe5..832af15678ef 100644 --- a/drivers/uio/uio_pci_generic.c +++ b/drivers/uio/uio_pci_generic.c @@ -39,6 +39,14 @@ to_uio_pci_generic_dev(struct uio_info *info) return container_of(info, struct uio_pci_generic_dev, info); } +static int release(struct uio_info *info, struct inode *inode) +{ + struct uio_pci_generic_dev *gdev = to_uio_pci_generic_dev(info); + /* Stop the device from initiating further DMAs */ + pci_clear_master(gdev->pdev); + return 0; +} + /* Interrupt handler. Read/modify/write the command register to disable * the interrupt. */ static irqreturn_t irqhandler(int irq, struct uio_info *info) @@ -78,6 +86,7 @@ static int probe(struct pci_dev *pdev, gdev->info.name = "uio_pci_generic"; gdev->info.version = DRIVER_VERSION; + gdev->info.release = release; gdev->pdev = pdev; if (pdev->irq) { gdev->info.irq = pdev->irq;