Received: by 10.192.165.156 with SMTP id m28csp1134262imm; Mon, 16 Apr 2018 14:51:28 -0700 (PDT) X-Google-Smtp-Source: AIpwx49SUSshRZRmMrevPtUkYVPdSqsy/FZZ979ezk8D1byUDirJK6elf2q/bV8JJJm2K9yfRNu0 X-Received: by 10.101.97.16 with SMTP id z16mr164925pgu.23.1523915488114; Mon, 16 Apr 2018 14:51:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523915488; cv=none; d=google.com; s=arc-20160816; b=DI8GaRtcmAP9P8Sl+aWvwp4lTO0nsaPQwVbUoB5EQfDAen1zH/WcdodcIiO9Puic6M fGnrZ0xmpFZYZVOf1l2z+4U2Cti0q50rsOJc2sZwEN+fuKHme1DY2OhnOXQ0H5bScaLo LjBAsT2+FwPJ/CjUDWKsRr9A9Y1D7gEyw7z99eFu3DiZspjpVYQXHvnfUCkAYOYmrqQH KHzLJZ5TVnhLHmUtJcKkFDLtrwKvxQ8ydGEe6qz5QoUD7/Is4jHia6Zn1BJWIlKGxdlA i8y8EvoW7aERRudHnxfkXM7BFmKeA1ijSmCXsdyqr+59Vv8/u2wblA6PNMdoYMu2dtqH YkmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=6+f8D0/0eHGsWF2GgO2d8r+b7V6PGHmlb51YxCm7lWg=; b=mnEyJgY9l6HOyfPSxoD2hCfXyLk1wd0+kE9sgDw9+wo80qtpZ95JpoDd7BkkpHMtmO nCFvtBi0TncOvUubEtp+EdAmaveUUfqMpp3vWhU062NLtR1CzWsiqtowfLVOU8pXBP6Z +qjZ5dAl2hq7oD+v0Xwi5KeFzkdLUPOSCunwPlHv0F/teh1jk0b2onasawXxWX/BI2Lc TIPpVuXji+zZ+bf/ZN6z0aaNvsonMUNAPs/vGQE6BXuSjsvVdQS777AJZavpuj3n8Cfz tokzgRZlZsjZyFY4Z1PD7U0Y3Tg0e0cwZAgbnKCMEYQvi8uADtTWVkfj4rSBi8XZy+Ep J4Zw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si10082993pgv.539.2018.04.16.14.51.14; Mon, 16 Apr 2018 14:51:28 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753032AbeDPVqu (ORCPT + 99 others); Mon, 16 Apr 2018 17:46:50 -0400 Received: from mga09.intel.com ([134.134.136.24]:12290 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752915AbeDPVqp (ORCPT ); Mon, 16 Apr 2018 17:46:45 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 14:46:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,460,1517904000"; d="scan'208";a="34740158" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 16 Apr 2018 14:46:42 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson , Jean-Philippe Brucker Cc: Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Jean Delvare , "Christoph Hellwig" , "Lu Baolu" , Jacob Pan Subject: [PATCH v4 08/22] iommu/vt-d: support flushing more translation cache types Date: Mon, 16 Apr 2018 14:48:57 -0700 Message-Id: <1523915351-54415-9-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When Shared Virtual Memory is exposed to a guest via vIOMMU, extended IOTLB invalidation may be passed down from outside IOMMU subsystems. This patch adds invalidation functions that can be used for additional translation cache types. Signed-off-by: Jacob Pan --- drivers/iommu/dmar.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/intel-iommu.h | 21 +++++++++++++++++++-- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index 38bb90f..71bfc73 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c @@ -1339,6 +1339,18 @@ void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, qi_submit_sync(&desc, iommu); } +void qi_flush_eiotlb(struct intel_iommu *iommu, u16 did, u64 addr, u32 pasid, + unsigned int size_order, u64 granu, bool global) +{ + struct qi_desc desc; + + desc.low = QI_EIOTLB_PASID(pasid) | QI_EIOTLB_DID(did) | + QI_EIOTLB_GRAN(granu) | QI_EIOTLB_TYPE; + desc.high = QI_EIOTLB_ADDR(addr) | QI_EIOTLB_GL(global) | + QI_EIOTLB_IH(0) | QI_EIOTLB_AM(size_order); + qi_submit_sync(&desc, iommu); +} + void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, u16 qdep, u64 addr, unsigned mask) { @@ -1360,6 +1372,38 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, qi_submit_sync(&desc, iommu); } +void qi_flush_dev_eiotlb(struct intel_iommu *iommu, u16 sid, + u32 pasid, u16 qdep, u64 addr, unsigned size, u64 granu) +{ + struct qi_desc desc; + + desc.low = QI_DEV_EIOTLB_PASID(pasid) | QI_DEV_EIOTLB_SID(sid) | + QI_DEV_EIOTLB_QDEP(qdep) | QI_DEIOTLB_TYPE; + desc.high |= QI_DEV_EIOTLB_GLOB(granu); + + /* If S bit is 0, we only flush a single page. If S bit is set, + * The least significant zero bit indicates the size. VT-d spec + * 6.5.2.6 + */ + if (!size) + desc.high = QI_DEV_EIOTLB_ADDR(addr) & ~QI_DEV_EIOTLB_SIZE; + else { + unsigned long mask = 1UL << (VTD_PAGE_SHIFT + size); + + desc.high = QI_DEV_EIOTLB_ADDR(addr & ~mask) | QI_DEV_EIOTLB_SIZE; + } + qi_submit_sync(&desc, iommu); +} + +void qi_flush_pasid(struct intel_iommu *iommu, u16 did, u64 granu, int pasid) +{ + struct qi_desc desc; + + desc.high = 0; + desc.low = QI_PC_TYPE | QI_PC_DID(did) | QI_PC_GRAN(granu) | QI_PC_PASID(pasid); + + qi_submit_sync(&desc, iommu); +} /* * Disable Queued Invalidation interface. */ diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index 678a0f4..c54bce1 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -262,6 +262,10 @@ enum { #define QI_PGRP_RESP_TYPE 0x9 #define QI_PSTRM_RESP_TYPE 0xa +#define QI_DID(did) (((u64)did & 0xffff) << 16) +#define QI_DID_MASK GENMASK(31, 16) +#define QI_TYPE_MASK GENMASK(3, 0) + #define QI_IEC_SELECTIVE (((u64)1) << 4) #define QI_IEC_IIDEX(idx) (((u64)(idx & 0xffff) << 32)) #define QI_IEC_IM(m) (((u64)(m & 0x1f) << 27)) @@ -293,8 +297,9 @@ enum { #define QI_PC_DID(did) (((u64)did) << 16) #define QI_PC_GRAN(gran) (((u64)gran) << 4) -#define QI_PC_ALL_PASIDS (QI_PC_TYPE | QI_PC_GRAN(0)) -#define QI_PC_PASID_SEL (QI_PC_TYPE | QI_PC_GRAN(1)) +/* PASID cache invalidation granu */ +#define QI_PC_ALL_PASIDS 0 +#define QI_PC_PASID_SEL 1 #define QI_EIOTLB_ADDR(addr) ((u64)(addr) & VTD_PAGE_MASK) #define QI_EIOTLB_GL(gl) (((u64)gl) << 7) @@ -304,6 +309,10 @@ enum { #define QI_EIOTLB_DID(did) (((u64)did) << 16) #define QI_EIOTLB_GRAN(gran) (((u64)gran) << 4) +/* QI Dev-IOTLB inv granu */ +#define QI_DEV_IOTLB_GRAN_ALL 0 +#define QI_DEV_IOTLB_GRAN_PASID_SEL 1 + #define QI_DEV_EIOTLB_ADDR(a) ((u64)(a) & VTD_PAGE_MASK) #define QI_DEV_EIOTLB_SIZE (((u64)1) << 11) #define QI_DEV_EIOTLB_GLOB(g) ((u64)g) @@ -332,6 +341,7 @@ enum { #define QI_RESP_INVALID 0x1 #define QI_RESP_FAILURE 0xf +/* QI EIOTLB inv granu */ #define QI_GRAN_ALL_ALL 0 #define QI_GRAN_NONG_ALL 1 #define QI_GRAN_NONG_PASID 2 @@ -504,8 +514,15 @@ extern void qi_flush_context(struct intel_iommu *iommu, u16 did, u16 sid, u8 fm, u64 type); extern void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type); +extern void qi_flush_eiotlb(struct intel_iommu *iommu, u16 did, u64 addr, + u32 pasid, unsigned int size_order, u64 type, bool global); extern void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, u16 qdep, u64 addr, unsigned mask); + +extern void qi_flush_dev_eiotlb(struct intel_iommu *iommu, u16 sid, + u32 pasid, u16 qdep, u64 addr, unsigned size, u64 granu); +extern void qi_flush_pasid(struct intel_iommu *iommu, u16 did, u64 granu, int pasid); + extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu); extern int dmar_ir_support(void); -- 2.7.4