Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp82800ybe; Thu, 5 Sep 2019 17:54:49 -0700 (PDT) X-Google-Smtp-Source: APXvYqySMBGUBChM7mT0fxCgNEuGR/PuxnllvIxHQBpy+/Hge5NH1Q+wbsiObzRqmCgxGh6/TtPF X-Received: by 2002:aa7:9a5b:: with SMTP id x27mr7170075pfj.232.1567731289333; Thu, 05 Sep 2019 17:54:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567731289; cv=none; d=google.com; s=arc-20160816; b=L/aMtiNSkWcYY5MN+dqk1niAR882+1bd7P9mizdbBMu9LK6zESEmsOE9SOw9gcL3A2 ERWEdt82frks0nlOep8CYaBjaS+Ei9X92zal2okeQvgkWDdr6GluqfcxTFkQLkhP9alF kWiZJZXLkDHk2TBYGnivL/iqUWM60gBDZ2XW79LmOaK0CZ5sdELC6+PQ7IlyV2h9owjx MgPVcsqVD0kYFkdVl7UHn1NK4fyKrl1RVhVhs9m2FlrmFiY+GWHjjNzhezkgm0PNsgxQ Z0PKkbmj4TW6kt5Hsy1EISXVtkw+XWw0I9AJUBWgmT9oTPazdA3wdd8hLfY0bS2Tyod9 Dedg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:mime-version:user-agent:date:message-id:cc:to :subject:from:dkim-signature; bh=zvuZJm/OeGnitqg6mopzWwdjJ0Sb1OWjOsDK5ScpN2k=; b=PQhTbGp1G4yv7YmTlshu/eXuXo69ZMUaSEvxrVQCe4s5dtalXTr06VrYxn8zERN5Wc l9WOjWL4RBY1xcV7xAtAvNRCMGMiNrMK/Z3yDUoLZWc1feP4m0MiQkdUcybMAWayirLM emxoEgPlqFwOhhnnjq6TxfHOFqdgxoWZyrkvCEP+WaAkV27Yc3LdtGJCstbxmfAf6g0U OpnMXulizRyBDnhq1OK7p0PXfYBjCEPn0Uo8qONVpHBWw5LWsNF6Aom4cyL7KlyvScCj 0F4vbf3IKdLAzfch+G6Wk1MWpeTPuPuq8di+GMb7XO+X+9hlYCv/2fuAR41L4dTAOFBr xseA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fm92g6MJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l5si3601913pjt.11.2019.09.05.17.54.33; Thu, 05 Sep 2019 17:54:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=fm92g6MJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389613AbfIERJv (ORCPT + 99 others); Thu, 5 Sep 2019 13:09:51 -0400 Received: from mail-ot1-f67.google.com ([209.85.210.67]:40502 "EHLO mail-ot1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731215AbfIERJu (ORCPT ); Thu, 5 Sep 2019 13:09:50 -0400 Received: by mail-ot1-f67.google.com with SMTP id y39so2931774ota.7 for ; Thu, 05 Sep 2019 10:09:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:message-id:date:user-agent:mime-version :content-language:content-transfer-encoding; bh=zvuZJm/OeGnitqg6mopzWwdjJ0Sb1OWjOsDK5ScpN2k=; b=fm92g6MJUiNSxClpUlSh5+9QxkTe9Rh6e+PN6S0HdCgK1xYCEHylPDWfFgsXzbSzVY 8tic8eObcyj6QB4OGaqYMR4F+jAqIOecKiDKfOk69dUs5tbdt4MD1Pmle3ypkjcUOF6C swexo56txxBOz0g++imEeemrFWDsG135wPPweBXrlulhzJGbK9yqHYoycVPku+PHJrfA 1TY767slE0gfetOwrAVel0tqMZnuoEMMjhAVFEcC+SwUvQzTg3t7grtqShIuShmYfrw7 7tMV+ktncJrXHJK1cU+oTbA1O1hC150dGKuz+mgVa3IGffGWcu2d+XnBtjQkMe86xo5H rzPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:message-id:date:user-agent :mime-version:content-language:content-transfer-encoding; bh=zvuZJm/OeGnitqg6mopzWwdjJ0Sb1OWjOsDK5ScpN2k=; b=uAJIGdyPNtp6S6RRckwrpIJnI7EI9jv0ndeCjtYz5JZjpgxS7qAXJw/68OdyGk0dhc cQhYh/HsiLF86Zx8JacL6Zvx9Q5mYYxe1F4BIEd01klzioIAZYIB1WFrlw447vS1LqvM mX0x0nrUHcwJNBiF9l5YrSLFHoxn8ndrmgLduBDJfsGbHpp0IX7WGhe9llEUuNVtCaAm L69iCWl20ZZ1wkSieqwdFVQEjfucYqb9r39H1hLuAtdfxP29vM6cHatFLI+UrNXDdl9M HXcrrcLwcFMCDss81JpbERYjG+WgZTmJ6JF+ed+CWzfpE8PDTQxPAVqtuJvKjFkEOpCb YeKg== X-Gm-Message-State: APjAAAVGkDnQEDj6PVbhsuxES58zY2Q++rxXJ0QhYBa9zbkKPvj1I+t9 A8pmddyRcHtzN5ef/Np2vrk= X-Received: by 2002:a05:6830:6:: with SMTP id c6mr3285609otp.331.1567703389824; Thu, 05 Sep 2019 10:09:49 -0700 (PDT) Received: from [100.71.96.87] ([143.166.81.254]) by smtp.gmail.com with ESMTPSA id b10sm669790oie.27.2019.09.05.10.09.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Sep 2019 10:09:49 -0700 (PDT) From: Stuart Hayes Subject: [PATCH] amd/iommu: flush old domains in kdump kernel To: jroedel@suse.de Cc: Linux Kernel Mailing List , iommu@lists.linux-foundation.org Message-ID: <9d271f88-949a-7356-c516-be95b1566c94@gmail.com> Date: Thu, 5 Sep 2019 12:09:48 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When devices are attached to the amd_iommu in a kdump kernel, the old device table entries (DTEs), which were copied from the crashed kernel, will be overwritten with a new domain number. When the new DTE is written, the IOMMU is told to flush the DTE from its internal cache--but it is not told to flush the translation cache entries for the old domain number. Without this patch, AMD systems using the tg3 network driver fail when kdump tries to save the vmcore to a network system, showing network timeouts and (sometimes) IOMMU errors in the kernel log. This patch will flush IOMMU translation cache entries for the old domain when a DTE gets overwritten with a new domain number. Signed-off-by: Stuart Hayes --- diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c index b607a92..f853b96 100644 --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -1143,6 +1143,17 @@ static void amd_iommu_flush_tlb_all(struct amd_iommu *iommu) iommu_completion_wait(iommu); } +static void amd_iommu_flush_tlb_domid(struct amd_iommu *iommu, u32 dom_id) +{ + struct iommu_cmd cmd; + + build_inv_iommu_pages(&cmd, 0, CMD_INV_IOMMU_ALL_PAGES_ADDRESS, + dom_id, 1); + iommu_queue_command(iommu, &cmd); + + iommu_completion_wait(iommu); +} + static void amd_iommu_flush_all(struct amd_iommu *iommu) { struct iommu_cmd cmd; @@ -1873,6 +1884,7 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, { u64 pte_root = 0; u64 flags = 0; + u32 old_domid; if (domain->mode != PAGE_MODE_NONE) pte_root = iommu_virt_to_phys(domain->pt_root); @@ -1922,8 +1934,20 @@ static void set_dte_entry(u16 devid, struct protection_domain *domain, flags &= ~DEV_DOMID_MASK; flags |= domain->id; + old_domid = amd_iommu_dev_table[devid].data[1] & DEV_DOMID_MASK; amd_iommu_dev_table[devid].data[1] = flags; amd_iommu_dev_table[devid].data[0] = pte_root; + + /* + * A kdump kernel might be replacing a domain ID that was copied from + * the previous kernel--if so, it needs to flush the translation cache + * entries for the old domain ID that is being overwritten + */ + if (old_domid) { + struct amd_iommu *iommu = amd_iommu_rlookup_table[devid]; + + amd_iommu_flush_tlb_domid(iommu, old_domid); + } } static void clear_dte_entry(u16 devid)