Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3934191imm; Mon, 8 Oct 2018 11:56:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV60XE19ph2n4igDH4VUeI3Qeitt72kMfsUSXFI0WwVky5lTvbfYZnKYNMxn6PGaH8U3WPqr1 X-Received: by 2002:a17:902:758f:: with SMTP id j15-v6mr25817806pll.160.1539024993552; Mon, 08 Oct 2018 11:56:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539024993; cv=none; d=google.com; s=arc-20160816; b=LGk109s6cHrFLP4q7auN9cMZuFhIHdFQLRKfTPdFKp5uX8kfoeqaqCWeBQUa06z2tB IXm3u2OYE47e/iGc42PSvQanuKpEJIciSABSmuiP8FJeEbAjbznFB/goDfLTiU4w1Dxu UG8fO9EGKCI2wpww169Q/HzGSVCCacu9/HD5WLd0/hBl4dOCRQG5iTlhcvUzO8KdlsNx m0VDCuCS1ZeFrwAklmAEkc6dE/zdj3gvjchv01SEV1WvfVKEF5HGM8o6LGVGG5TZMpup i3tiDy/Ss/yFnrtesJh3X7n1nQyptjaUwBQ6hoAhEH6IG3S/Kji5r882rHOYdRdzRQi+ oL3g== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LTiLeKQj5treBzZGka2e7bdfNhEdArwcf6Vhyt651Hc=; b=Jn/7qwxFcRXYipCd9r25lPU47TIjP44xsU6WLStx9cabFt99znUCj+xwMiyTs2jELf uyIVALFgCCKWDykcCNypV1Pi8V399CA3ioHCh9RlbfY+AjTSwFlgBM63EU39V5lyDHX3 s69U8St4pX+ggmYdl8r9yodr6vi1GcR9VLxrehoKOYOaDfCf/sfvHl9v111Gx4TDFNb0 Q+pUHruMn3TShEaAUtUjG17U4M4w4hFMUcZ7dFnLCnYv7BNjwtr4fWCZJC/E2GXiKFsX sAcZZytc6E1lNBvP1rZjHm5eFCBny3P5PA5I2iH882WnwlZkQp8He36wDEf6ybwNMzbr uCzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HyMzOWLQ; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h18-v6si18664203pgk.351.2018.10.08.11.56.17; Mon, 08 Oct 2018 11:56:33 -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=@kernel.org header.s=default header.b=HyMzOWLQ; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732706AbeJICGX (ORCPT + 99 others); Mon, 8 Oct 2018 22:06:23 -0400 Received: from mail.kernel.org ([198.145.29.99]:56692 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729253AbeJICGW (ORCPT ); Mon, 8 Oct 2018 22:06:22 -0400 Received: from localhost (ip-213-127-77-176.ip.prioritytelecom.net [213.127.77.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3B38D204FD; Mon, 8 Oct 2018 18:53:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1539024793; bh=2PRRWKqD93nto6N2HRIpBvTazSvuUJsboEHXb3NKU7c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HyMzOWLQfDxxSRDhnMz36i5tIp1hHo35xsWlcDTzVH9Zs1TaRjvW4/FraK3OvlJjR J3kNorYCmYrRb5pNPHkkpzmyl9fcATaUs+APBd9RrR/z7u5rfRlIugkZ23nHD6X6Fx /p6c6vnMJ+M275hOZhH/QMOYzpteQlaCtEAO3X+0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Boris Ostrovsky , Tom Lendacky , Joerg Roedel , iommu@lists.linux-foundation.org, Borislav Petkov , Paolo Bonzini , =?UTF-8?q?Radim=20Kr=C4=8Dm=C3=A1=C5=99?= , kvm@vger.kernel.org, Brijesh Singh , Joerg Roedel Subject: [PATCH 4.18 156/168] iommu/amd: Clear memory encryption mask from physical address Date: Mon, 8 Oct 2018 20:32:16 +0200 Message-Id: <20181008175625.978463772@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181008175620.043587728@linuxfoundation.org> References: <20181008175620.043587728@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Singh, Brijesh commit b3e9b515b08e407ab3a026dc2e4d935c48d05f69 upstream. Boris Ostrovsky reported a memory leak with device passthrough when SME is active. The VFIO driver uses iommu_iova_to_phys() to get the physical address for an iova. This physical address is later passed into vfio_unmap_unpin() to unpin the memory. The vfio_unmap_unpin() uses pfn_valid() before unpinning the memory. The pfn_valid() check was failing because encryption mask was part of the physical address returned. This resulted in the memory not being unpinned and therefore leaked after the guest terminates. The memory encryption mask must be cleared from the physical address in iommu_iova_to_phys(). Fixes: 2543a786aa25 ("iommu/amd: Allow the AMD IOMMU to work with memory encryption") Reported-by: Boris Ostrovsky Cc: Tom Lendacky Cc: Joerg Roedel Cc: Cc: Borislav Petkov Cc: Paolo Bonzini Cc: Radim Krčmář Cc: kvm@vger.kernel.org Cc: Boris Ostrovsky Cc: # 4.14+ Signed-off-by: Brijesh Singh Signed-off-by: Joerg Roedel Signed-off-by: Greg Kroah-Hartman --- drivers/iommu/amd_iommu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/iommu/amd_iommu.c +++ b/drivers/iommu/amd_iommu.c @@ -3073,7 +3073,7 @@ static phys_addr_t amd_iommu_iova_to_phy return 0; offset_mask = pte_pgsize - 1; - __pte = *pte & PM_ADDR_MASK; + __pte = __sme_clr(*pte & PM_ADDR_MASK); return (__pte & ~offset_mask) | (iova & offset_mask); }