Received: by 2002:ac2:5e6c:0:0:0:0:0 with SMTP id a12csp3056623lfr; Sun, 11 Apr 2021 05:16:45 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWIg89UGBHCM+HAs+0fo++3dmyBEmpasr0aV//PVv96rQ62OtAqNim4RlgRe3SsAjraimk X-Received: by 2002:a05:6638:6ae:: with SMTP id d14mr8329685jad.77.1618143405495; Sun, 11 Apr 2021 05:16:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618143405; cv=none; d=google.com; s=arc-20160816; b=btRdgYAxlKwIs+fakzxXRDI3rvYw9P7YJOcxHP+jmYEZxn7olOI8II2+ity/+HSMDx py9eNWJSMl2HZqWBbyYqzuMp9vzDszXKfYPcx1+QnrQb8vnIKIWgxIiABN78BeG9lWeV X2nzsTLu6C3qes0M2rTRAaU7iYlthce2QzS9C1zi3T6js16uS41xTZC85gI4e8K78nzh zTFX4dtSFMGyt6wpS6iNnqBKKqR58jYwsZEyBjD8JBu0aGK+sthA4Z5M0Y9OnfLrAe7r ximlEWpD7VsxC0cDjG67tpbrx67aDMj3+7HxYaaNAG0vLLHSHP8oOQQUveW2DMIXHJAC s+gA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=R9NPsslFaBP70t3qucG6hbsDRR184R0H4Zo7SVEUzRM=; b=h6EqIZ+40XcxRdNC/gaH2CPdQyWaKhelO70SkTpbvTmTf8qLa3mQDC+2Fe/A8JPeoF wW+PL4CwQ4EXiUIW5Ji9SyntgLBAfj42AU3vlOrubnecdzves82fDE137bUVTvKnrZS3 DoIibxuMg4gF7mhpXttAEEp+1AKOP3WmNEU8X+jFP/0ozdlDVw6CIqTxBS4gdclg8Axj qHFBtPf4oed2BmCuwI/P8LjMedpkovshYa/R1XcIbJZaDx/fhsBc/CsLGr5shD/jFJQR k3v+JvcsdeLJWiVLt/NdconBvlahJ7jZs8Rpc08aZW04c5wIbCpaCKGAw+Co2Gs2fl8B ZWSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=NceOAH3o; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id g12si9461836iow.63.2021.04.11.05.16.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Apr 2021 05:16:45 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@redhat.com header.s=mimecast20190719 header.b=NceOAH3o; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from localhost ([::1]:33334 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lVZ1A-0004Av-Nv for alex.bennee@linaro.org; Sun, 11 Apr 2021 08:16:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:47446) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVYw2-0000eI-6C for qemu-arm@nongnu.org; Sun, 11 Apr 2021 08:11:26 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52804) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lVYvy-0002ow-6X for qemu-arm@nongnu.org; Sun, 11 Apr 2021 08:11:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618143075; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=R9NPsslFaBP70t3qucG6hbsDRR184R0H4Zo7SVEUzRM=; b=NceOAH3oTruT/yLj3/g+n6osqY3ALYHkdPVHXPXUc+y3Dc54qmHb9/tAagyVjrD40+T/nq SH80zSmJVjGcqUg3mAaIswng/oeAUF4e09zrgYy56SmwXDCTRK5oQcx0di0nWykSZdrmco lBZ7J1OeutfwHwcew24wZr9VGcuwOb4= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-144-sNg-dZz1M6e8OQX1k6YVVg-1; Sun, 11 Apr 2021 08:11:11 -0400 X-MC-Unique: sNg-dZz1M6e8OQX1k6YVVg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E9C64802B56; Sun, 11 Apr 2021 12:11:09 +0000 (UTC) Received: from laptop.redhat.com (ovpn-112-22.ams2.redhat.com [10.36.112.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3FD0210023B2; Sun, 11 Apr 2021 12:11:04 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, qemu-devel@nongnu.org, qemu-arm@nongnu.org, alex.williamson@redhat.com Subject: [RFC v9 09/29] memory: Introduce IOMMU Memory Region inject_faults API Date: Sun, 11 Apr 2021 14:08:52 +0200 Message-Id: <20210411120912.15770-10-eric.auger@redhat.com> In-Reply-To: <20210411120912.15770-1-eric.auger@redhat.com> References: <20210411120912.15770-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eric.auger@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Received-SPF: pass client-ip=170.10.133.124; envelope-from=eric.auger@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, jacob.jun.pan@linux.intel.com, jean-philippe@linaro.org, tn@semihalf.com, chenxiang66@hisilicon.com, jiangkunkun@huawei.com, shameerali.kolothum.thodi@huawei.com, nicoleotsuka@gmail.com, vivek.gautam@arm.com, vdumpa@nvidia.com, yi.l.liu@intel.com, peterx@redhat.com, zhangfei.gao@gmail.com, yuzenghui@huawei.com, zhukeqian1@huawei.com Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: "Qemu-arm" X-TUID: lxj7SZwZCESP This new API allows to inject @count iommu_faults into the IOMMU memory region. Signed-off-by: Eric Auger --- include/exec/memory.h | 24 ++++++++++++++++++++++++ softmmu/memory.c | 10 ++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/exec/memory.h b/include/exec/memory.h index ac8521b29a..527f77c453 100644 --- a/include/exec/memory.h +++ b/include/exec/memory.h @@ -65,6 +65,8 @@ struct ReservedRegion { unsigned type; }; +struct iommu_fault; + typedef struct IOMMUTLBEntry IOMMUTLBEntry; /* See address_space_translate: bit 0 is read, bit 1 is write. */ @@ -475,6 +477,19 @@ struct IOMMUMemoryRegionClass { int (*iommu_set_page_size_mask)(IOMMUMemoryRegion *iommu, uint64_t page_size_mask, Error **errp); + + /* + * Inject @count faults into the IOMMU memory region + * + * Optional method: if this method is not provided, then + * memory_region_injection_faults() will return -ENOENT + * + * @iommu: the IOMMU memory region to inject the faults in + * @count: number of faults to inject + * @buf: fault buffer + */ + int (*inject_faults)(IOMMUMemoryRegion *iommu, int count, + struct iommu_fault *buf); }; typedef struct CoalescedMemoryRange CoalescedMemoryRange; @@ -1520,6 +1535,15 @@ int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr); int memory_region_iommu_set_page_size_mask(IOMMUMemoryRegion *iommu_mr, uint64_t page_size_mask, Error **errp); +/** + * memory_region_inject_faults : inject @count faults stored in @buf + * + * @iommu_mr: the IOMMU memory region + * @count: number of faults to be injected + * @buf: buffer containing the faults + */ +int memory_region_inject_faults(IOMMUMemoryRegion *iommu_mr, int count, + struct iommu_fault *buf); /** * memory_region_name: get a memory region's name diff --git a/softmmu/memory.c b/softmmu/memory.c index d4493ef9e4..1dd34356c0 100644 --- a/softmmu/memory.c +++ b/softmmu/memory.c @@ -2030,6 +2030,16 @@ int memory_region_iommu_num_indexes(IOMMUMemoryRegion *iommu_mr) return imrc->num_indexes(iommu_mr); } +int memory_region_inject_faults(IOMMUMemoryRegion *iommu_mr, int count, + struct iommu_fault *buf) +{ + IOMMUMemoryRegionClass *imrc = IOMMU_MEMORY_REGION_GET_CLASS(iommu_mr); + if (!imrc->inject_faults) { + return -ENOENT; + } + return imrc->inject_faults(iommu_mr, count, buf); +} + void memory_region_set_log(MemoryRegion *mr, bool log, unsigned client) { uint8_t mask = 1 << client; -- 2.26.3