Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp759122ybb; Wed, 8 Apr 2020 09:19:36 -0700 (PDT) X-Google-Smtp-Source: APiQypK0geBK7/whc/nr+9h6zd8CSAItQ4+dQW0myGndNtZL8gYWyyoyJA7uUNNmmy2qvglSBAkz X-Received: by 2002:a9d:67c5:: with SMTP id c5mr422771otn.79.1586362776556; Wed, 08 Apr 2020 09:19:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586362776; cv=none; d=google.com; s=arc-20160816; b=lZdI2koEc6qPBNqdG0luIa7lSGBf9oxHAZ62Q4wbUYInkYJFYGDWvOfkpEAEOqliXC 2+Wdj6t/Cz26XjThe0sUHW3yYZU38wsnH2qHYHtTxeNDojYE8yNIX6d9hY1qpR/mu9iL ji2hGqTjaJrd2OLy+XE1da9jh+B8yVqa0W2QzyBJRHX48LtD4tjpwzg8W7CI8zfm2VOW FddaSiPHP+1oL9YYt0aWyr1QKPxmO6kCXk14HOLmaxmyvSf/J4ETJeBsrQMmAsfed0OC M0vX8kekFzajswaXPHndl49iC2pGhTuN2oqNb//bkTZZyFJRvO/fkWIP4zjBHlKQtmRV 6gfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Cw4i32n4xKGtttnqfVBXGMil3gN53t3h4YytcDyfbt4=; b=auoN9wUunA7D3Nq2ncfsVwuNKKlwDoN8xdxNOim8eCT1jdto3UqF77BX/f1EPmD/4M B4I+2tDs10xk0ArfO1T2zOrhXGBuXm0ZXDMizXXLBwpqJI6EGbU1pxjrua1bna1hu4Ff HIVVdZk4o8a7TjW1AGSimMn4UnTPV6iP5bE7JCEXeG62lB8TwUPHa7+zxLHQq6Zhr5NP dZb7fjrTcoRuiSNpw5EgFSH64TULdHLmlj20cbZsnBNSCoy3rFgLS77TKbUefgETqRLE l/WcAagYoWx7QANpyGoYyoUIfaW2UOXs81T4mH+jDJNI9qACTSV5P4i+CWp2L4msuL1n 9RgA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r67si2247793oib.237.2020.04.08.09.19.13; Wed, 08 Apr 2020 09:19:36 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=8bytes.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728474AbgDHOTS (ORCPT + 99 others); Wed, 8 Apr 2020 10:19:18 -0400 Received: from 8bytes.org ([81.169.241.247]:58562 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726550AbgDHOTS (ORCPT ); Wed, 8 Apr 2020 10:19:18 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id A7BD32B6; Wed, 8 Apr 2020 16:19:16 +0200 (CEST) Date: Wed, 8 Apr 2020 16:19:15 +0200 From: Joerg Roedel To: Qian Cai Cc: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] iommu/amd: fix a race in fetch_pte() Message-ID: <20200408141915.GJ3103@8bytes.org> References: <20200407021246.10941-1-cai@lca.pw> <7664E2E7-04D4-44C3-AB7E-A4334CDEC373@lca.pw> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7664E2E7-04D4-44C3-AB7E-A4334CDEC373@lca.pw> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Qian, On Tue, Apr 07, 2020 at 11:36:05AM -0400, Qian Cai wrote: > After further testing, the change along is insufficient. What I am chasing right > now is the swap device will go offline after heavy memory pressure below. The > symptom is similar to what we have in the commit, > > 754265bcab78 (“iommu/amd: Fix race in increase_address_space()”) > > Apparently, it is no possible to take the domain->lock in fetch_pte() because it > could sleep. Thanks a lot for finding and tracking down another race in the AMD IOMMU page-table code. The domain->lock is a spin-lock and taking it can't sleep. But fetch_pte() is a fast-path and must not take any locks. I think the best fix is to update the pt_root and mode of the domain atomically by storing the mode in the lower 12 bits of pt_root. This way they are stored together and can be read/write atomically. Regards, Joerg