Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1105078pxa; Thu, 20 Aug 2020 02:36:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyE+B/LGL/+WD6cMvrBj4K84/XwK5Am3lgWxbfFmQwLvkpJkr4ATniMVomkOZSbfzNuUyaB X-Received: by 2002:a17:906:cc4d:: with SMTP id mm13mr2265946ejb.191.1597916178135; Thu, 20 Aug 2020 02:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597916178; cv=none; d=google.com; s=arc-20160816; b=hPk1T/o5NyEvTUYtujhpQrHPJhL2UCDdgiGT3xkMcHlHEFAhUZr0GFeLYYjubqHns4 1wsU5AORkzm1JUbzp8ckuAL1Aitc+/+a6Y9xvkcsVEjBNlVDh4goXiP1gogxe9UUF0mV 4PP+1LyfTLph4ZZIOsl7F+kXrEoZRPtE0jkQYt3+wBIxTN4NJWFs6vco3K2fg0E8EzaV xBDSsdp3sto6Ww7IMA8zWnofSKm+1VVsgcIFH7ur6Lu5V6G8B6ZXrbEz6Bf3lbv7yrPo CFzPz9k1n1Af/J6GrcZI7FUUVXepynuUf9Sz0toGOG1VvyjiqhcbfNrsrr6JBRn8lG/s 2xAQ== 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=dp2IJymt3Vk8w0VQkqkXAY5d6Q2jLeuF0ljBZEvXRjs=; b=yqzKzIoyNfe7aSbgwErJIrzZHFTR23nu7cYUTovXSQ+RYRKzxiqEwkLc6MvDqgeEBR UdT24kOMjoK5oCRGDbcAsNG6coXFi65SYAj0zSy39tf9yLAeG7EmkBPiyNBECcH8GE4K QJE4BAvirLNxt6g4TNBqfpW0VmzZNF3tVVjkxbZU50yeycw3WTN2/QmTCMfM3dAhh+qd 2vsG6hq0O2G4jWEczJb0UbsU4Sg/lGRT0C32IW5R97coabZKnxjwzxYjV0Cg5NNH6kR8 AT1O73+Ru2cW4vdL7PoxSS/7V1uAZG0rG0UuZc8N9Ytdy9KcoU20EhAuHUpqvG90zTGW xYdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qgj9ds9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si895513ejx.257.2020.08.20.02.35.54; Thu, 20 Aug 2020 02:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Qgj9ds9u; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728475AbgHTJfK (ORCPT + 99 others); Thu, 20 Aug 2020 05:35:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:44582 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727779AbgHTJcO (ORCPT ); Thu, 20 Aug 2020 05:32:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 2C64722B4B; Thu, 20 Aug 2020 09:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915933; bh=Do5+tr33I6sMu+dO/0UB/wx1YwNFPXRVPUGKAE7s/BM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qgj9ds9uXvKfXCmq1oVZfx+PwQQwMtXRP0grVETzM1EN2Yoi/2w+t8u0aB+ebIUOV Yse+Z38QXNLCt6R3+AOuVD7DME2g7hro/n2dlWtpC/MM4TskiJ2LoQ0jWu2FB+Kwhx hGfutIkSsS13OfpkHLJMbUUlforlsd5DUsGJGBOc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Liu Yi L , Jacob Pan , Lu Baolu , Eric Auger , Joerg Roedel , Sasha Levin Subject: [PATCH 5.8 158/232] iommu/vt-d: Handle non-page aligned address Date: Thu, 20 Aug 2020 11:20:09 +0200 Message-Id: <20200820091620.465486065@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Liu Yi L [ Upstream commit 288d08e78008828416ffaa85ef274b4e29ef3dae ] Address information for device TLB invalidation comes from userspace when device is directly assigned to a guest with vIOMMU support. VT-d requires page aligned address. This patch checks and enforce address to be page aligned, otherwise reserved bits can be set in the invalidation descriptor. Unrecoverable fault will be reported due to non-zero value in the reserved bits. Fixes: 61a06a16e36d8 ("iommu/vt-d: Support flushing more translation cache types") Signed-off-by: Liu Yi L Signed-off-by: Jacob Pan Signed-off-by: Lu Baolu Reviewed-by: Eric Auger Link: https://lore.kernel.org/r/20200724014925.15523-5-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel Signed-off-by: Sasha Levin --- drivers/iommu/intel/dmar.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/intel/dmar.c b/drivers/iommu/intel/dmar.c index 16f47041f1bf5..ec23a2f0b5f8d 100644 --- a/drivers/iommu/intel/dmar.c +++ b/drivers/iommu/intel/dmar.c @@ -1459,9 +1459,26 @@ void qi_flush_dev_iotlb_pasid(struct intel_iommu *iommu, u16 sid, u16 pfsid, * Max Invs Pending (MIP) is set to 0 for now until we have DIT in * ECAP. */ - desc.qw1 |= addr & ~mask; - if (size_order) + if (addr & GENMASK_ULL(size_order + VTD_PAGE_SHIFT, 0)) + pr_warn_ratelimited("Invalidate non-aligned address %llx, order %d\n", + addr, size_order); + + /* Take page address */ + desc.qw1 = QI_DEV_EIOTLB_ADDR(addr); + + if (size_order) { + /* + * Existing 0s in address below size_order may be the least + * significant bit, we must set them to 1s to avoid having + * smaller size than desired. + */ + desc.qw1 |= GENMASK_ULL(size_order + VTD_PAGE_SHIFT - 1, + VTD_PAGE_SHIFT); + /* Clear size_order bit to indicate size */ + desc.qw1 &= ~mask; + /* Set the S bit to indicate flushing more than 1 page */ desc.qw1 |= QI_DEV_EIOTLB_SIZE; + } qi_submit_sync(iommu, &desc, 1, 0); } -- 2.25.1