From patchwork Thu Apr 20 15:17:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cindy Lu X-Patchwork-Id: 85937 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp424639vqo; Thu, 20 Apr 2023 08:33:18 -0700 (PDT) X-Google-Smtp-Source: AKy350bJZAke+smF0zTVcrlY9GvdgLlksVjERoYLBLFcWouBiAaFM+E3t9WdWqVGi6AFiEfJ4PO8 X-Received: by 2002:a05:6a21:1519:b0:f0:e69:748c with SMTP id nq25-20020a056a21151900b000f00e69748cmr2480080pzb.58.1682004798464; Thu, 20 Apr 2023 08:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682004798; cv=none; d=google.com; s=arc-20160816; b=Uhqa5uSXTDwUFU137HEgvif8pT7FPgst4ctpMN90AyPAz1NehOXUs2lSARIdUTkYqZ OwxwBmWOb5V98Bj3w/Iza2EigwijIbg1P9LG6OwWol8y2aHu/bnEay4ECGdDxXJzddYd YaPPHYye2rR3N+YhIdzGb7iYcSpr9Zad5gs9zA3Ev99nPFmFJbk+7R5tNfS+3RbJDwNo tN9FWchFZd7nX22lAp2sRhtv2aJUC2OHXCffNX6qF63LOZ67wRut7wLCmakbnxEp0y5A ZKPrKxWRLtlRW/+q6hanavE5n0paE4gKhL6MP0STCaHklCbfaF1yf6vfNm1UNtp07Bzn t9lA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=T8ZLh/+9pFKOaUcevCs3WZu/2q9L2xhWGPZeouIGDG8=; b=bo2hSpSL79BIbsjWTfuGQp6Bta/MCxCzRBqQ4AfuYJCbP1af67L9xxb0HBgDIW5YdG Y6pkffuJo9uoKKqGT0ZXl5LO9VCpusqPbNFKEv+QqcYxROTVCgd3l4MHj5SJEFORdb8O 24LwLckp5OLoqHinRlFPHss7Vh9Bbcorx+IcJ+WZ5jxeUFSdVoASyLdW3hNsxSARgFo7 OdmPf4VZZz9plt6u4V4wa5rGpULuur+0VypguKMOa8nGxR/3PwA8d8pK/ce4ZXeVxIDV KyKXiul0KV5EpKr6VRVLkYQYsSyn5Vhpp+f2etubHnF5V8CvLG4RqeBtonzGDF27rcZV H62Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cN8Zfin2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s85-20020a632c58000000b00519a8f54d2bsi1874927pgs.667.2023.04.20.08.32.56; Thu, 20 Apr 2023 08:33:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cN8Zfin2; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233174AbjDTPSm (ORCPT + 99 others); Thu, 20 Apr 2023 11:18:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232078AbjDTPSk (ORCPT ); Thu, 20 Apr 2023 11:18:40 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B2F655B8 for ; Thu, 20 Apr 2023 08:17:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682003868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=T8ZLh/+9pFKOaUcevCs3WZu/2q9L2xhWGPZeouIGDG8=; b=cN8Zfin2U1H7mbC1SZZJo7wfGs9m5QmdytFDJohLRv+QIN9xE126o6kotTE8mxky+LvcOk 8JVeliyn/5jxY6ffqBcl2RcmCdEdIsRX79pOvR+Vq+dwPqzzrbthadaRB2IO4W91+D3UWI 9BDLfuYLLhir0N6Gup1+Ys///UvviDg= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-404-KhazK3lHOkWHXRfzgWa-YQ-1; Thu, 20 Apr 2023 11:17:45 -0400 X-MC-Unique: KhazK3lHOkWHXRfzgWa-YQ-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D27A9101A54F; Thu, 20 Apr 2023 15:17:44 +0000 (UTC) Received: from server.redhat.com (ovpn-13-47.pek2.redhat.com [10.72.13.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7DFB440C2064; Thu, 20 Apr 2023 15:17:41 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Cc: stable@vger.kernel.org Subject: [PATCH v3] vhost_vdpa: fix unmap process in no-batch mode Date: Thu, 20 Apr 2023 23:17:34 +0800 Message-Id: <20230420151734.860168-1-lulu@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.1 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763709863049349692?= X-GMAIL-MSGID: =?utf-8?q?1763709863049349692?= While using the vdpa device with vIOMMU enabled in the guest VM, when the vdpa device bind to vfio-pci and run testpmd then system will fail to unmap. The test process is Load guest VM --> attach to virtio driver--> bind to vfio-pci driver So the mapping process is 1)batched mode map to normal MR 2)batched mode unmapped the normal MR 3)unmapped all the memory 4)mapped to iommu MR This error happened in step 3). The iotlb was freed in step 2) and the function vhost_vdpa_process_iotlb_msg will return fail Which causes failure. To fix this, we will not remove the AS while the iotlb->nmaps is 0. This will free in the vhost_vdpa_clean Cc: stable@vger.kernel.org Fixes: aaca8373c4b1 ("vhost-vdpa: support ASID based IOTLB API") Signed-off-by: Cindy Lu Acked-by: Jason Wang --- drivers/vhost/vdpa.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/vhost/vdpa.c b/drivers/vhost/vdpa.c index 7be9d9d8f01c..74c7d1f978b7 100644 --- a/drivers/vhost/vdpa.c +++ b/drivers/vhost/vdpa.c @@ -851,11 +851,7 @@ static void vhost_vdpa_unmap(struct vhost_vdpa *v, if (!v->in_batch) ops->set_map(vdpa, asid, iotlb); } - /* If we are in the middle of batch processing, delay the free - * of AS until BATCH_END. - */ - if (!v->in_batch && !iotlb->nmaps) - vhost_vdpa_remove_as(v, asid); + } static int vhost_vdpa_va_map(struct vhost_vdpa *v, @@ -1112,8 +1108,6 @@ static int vhost_vdpa_process_iotlb_msg(struct vhost_dev *dev, u32 asid, if (v->in_batch && ops->set_map) ops->set_map(vdpa, asid, iotlb); v->in_batch = false; - if (!iotlb->nmaps) - vhost_vdpa_remove_as(v, asid); break; default: r = -EINVAL;