From patchwork Fri Apr 27 19:00:33 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Khalid Aziz X-Patchwork-Id: 155574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 18B39B6FE0 for ; Sat, 28 Apr 2012 05:00:36 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761222Ab2D0TAe (ORCPT ); Fri, 27 Apr 2012 15:00:34 -0400 Received: from g4t0014.houston.hp.com ([15.201.24.17]:44320 "EHLO g4t0014.houston.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758940Ab2D0TAe (ORCPT ); Fri, 27 Apr 2012 15:00:34 -0400 Received: from g4t0009.houston.hp.com (g4t0009.houston.hp.com [16.234.32.26]) by g4t0014.houston.hp.com (Postfix) with ESMTP id 7DDCC240A6; Fri, 27 Apr 2012 19:00:33 +0000 (UTC) Received: from ldl (ldl.usa.hp.com [16.125.112.222]) by g4t0009.houston.hp.com (Postfix) with ESMTP id 74ADFC8CA; Fri, 27 Apr 2012 19:00:33 +0000 (UTC) Received: from localhost (ldl.fc.hp.com [127.0.0.1]) by ldl (Postfix) with ESMTP id 3FC061A7E0E5; Fri, 27 Apr 2012 13:00:33 -0600 (MDT) Received: from ldl ([127.0.0.1]) by localhost (ldl.fc.hp.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SDbmj4gnQwY1; Fri, 27 Apr 2012 13:00:33 -0600 (MDT) Received: by ldl (Postfix, from userid 29214) id 1E4121A7E0EC; Fri, 27 Apr 2012 13:00:33 -0600 (MDT) Date: Fri, 27 Apr 2012 13:00:33 -0600 From: Khalid Aziz To: linux-kernel@vger.kernel.org Cc: bhelgaas@google.com, linux-pci@vger.kernel.org Subject: [PATCH] Disable Bus Master on PCI device shutdown Message-ID: <20120427190033.GA17588@ldl.usa.hp.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Disable Bus Master bit on the device in pci_device_shutdown() to ensure PCI devices do not continue to DMA data after shutdown. This can cause memory corruption in case of a kexec where the current kernel shuts down and transfers control to a new kernel while a PCI device continues to DMA to memory that does not belong to it any more in the new kernel. I have tested this code on two laptops, two workstations and a 16-socket server. kexec worked correctly on all of them. Signed-off-by: Khalid Aziz --- drivers/pci/pci-driver.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c index 6b54b23..9db5940 100644 --- a/drivers/pci/pci-driver.c +++ b/drivers/pci/pci-driver.c @@ -420,6 +420,12 @@ static void pci_device_shutdown(struct device *dev) pci_msi_shutdown(pci_dev); pci_msix_shutdown(pci_dev); + /* + * Turn off Bus Master bit on the device to tell it to not + * continue to do DMA + */ + pci_disable_device(pci_dev); + /* * Devices may be enabled to wake up by runtime PM, but they need not * be supposed to wake up the system from its "power off" state (e.g.