Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp18881253rwd; Wed, 28 Jun 2023 01:51:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7YUUzCALjcc0IEGhFwhogx9HCeJggy2KDyubQFrNPLM7mnkOc3fVruFnAyoFXJSrR3Zv1V X-Received: by 2002:a17:907:844:b0:982:9dc1:a434 with SMTP id ww4-20020a170907084400b009829dc1a434mr30975602ejb.19.1687942311783; Wed, 28 Jun 2023 01:51:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687942311; cv=none; d=google.com; s=arc-20160816; b=ri05OD6kYjOjxAvUoFRqX0o7Wkawmsh8fGErI79qYe4/NjKxQ5+fLoxPc72uDZ0lPh CZ4uomQiI/Gk9dXNJePSFKEdTithSOOa9pMTxkXovx5hy4mtwaJSYFiL1yDSFL/9e4um RmPTu5HJDtOLIiCPWIi6Bg2apU0qvoOnq/XoB3AKX4jgTuH+I4C1IbKkQtPUh0B/uc1I /jWyHJGJ2Tdql6PV/16Ib9ogUTuT1syBzMESGHKXhJMuMBv6loo76qG5kUA2z/c5xyBa j9gTV3bY9VczAgJW/zZ5MWYZhr2AhE6UBup+W9tuE9ShUnBIdD/ZLK5Hf1oUMvRh3dPe oW4w== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Vm8YdVuG5g/R4Upgn7ExptiiekTMB39MDE6nGXwwg5I=; fh=NOG8CJEG4WJu4DlPLKvyF6THcrTOjShCi1CeGqtRM/E=; b=TAEpRsMigW+wrB1q0OmqsLU92BdFwJyvpuY0UTnrWOOUjkn1BQ3jyL1Ag9Ea6RD/K+ d3WzIAPOCIJbet6YblSXSOdlB3IuOhdNPybDf25n63YLVKlaU0/qr6mDlpqZ4NJ6BvCn 6YmXfAsrqpjSo3pFPH9deYMR3KEk+1TvVnF9ECgn0c7l5bpXAfj8r/7PjDBLAbHgXXRf Bs2W/WIJvsJ2mTFbPjcDanCVpDtge1Maz6bIuapdkgxqRtFJFYRAtYZwfjIv6IFwVquk FeeuF+q6Npgsei682jQQ40G3ZObXj9Rxi5knbVCQ7VdT7dx3qJ7Bfby7UwzJL5TlYMnv QL5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VjQCD5ww; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z16-20020aa7d410000000b0051d89920c9asi4379349edq.149.2023.06.28.01.51.27; Wed, 28 Jun 2023 01:51:51 -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=VjQCD5ww; 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 S232260AbjF1IHU (ORCPT + 99 others); Wed, 28 Jun 2023 04:07:20 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:52113 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232381AbjF1ICI (ORCPT ); Wed, 28 Jun 2023 04:02:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687939278; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Vm8YdVuG5g/R4Upgn7ExptiiekTMB39MDE6nGXwwg5I=; b=VjQCD5ww+atNz7E0gkOSJimMS+f4FzL+KHIZTPOn5kqIvhrMthos20OyL1sKlV6XApFywx kn1BpotXG/445D5kwN32zmafAcJpRRr9gBfQh/GWnuyFUCK63OEjaxzYXrAOYBkEh6+XSB aUHF86FmaT9lQrcGcFIQ9vO88WUA8Ls= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-115-wEAlpELWNdCfebbpAG2Kmg-1; Wed, 28 Jun 2023 02:59:39 -0400 X-MC-Unique: wEAlpELWNdCfebbpAG2Kmg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 379003C025C7; Wed, 28 Jun 2023 06:59:39 +0000 (UTC) Received: from server.redhat.com (ovpn-13-142.pek2.redhat.com [10.72.13.142]) by smtp.corp.redhat.com (Postfix) with ESMTP id A62E0492B02; Wed, 28 Jun 2023 06:59:35 +0000 (UTC) From: Cindy Lu To: lulu@redhat.com, jasowang@redhat.com, mst@redhat.com, maxime.coquelin@redhat.com, xieyongji@bytedance.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org, netdev@vger.kernel.org Subject: [RFC 3/4] vduse: Add the function for get/free the mapp pages Date: Wed, 28 Jun 2023 14:59:18 +0800 Message-Id: <20230628065919.54042-4-lulu@redhat.com> In-Reply-To: <20230628065919.54042-1-lulu@redhat.com> References: <20230628065919.54042-1-lulu@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Your Name Add the function for get/free pages, ad this info will saved in dev->reconnect_info Signed-off-by: Cindy Lu --- drivers/vdpa/vdpa_user/vduse_dev.c | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/drivers/vdpa/vdpa_user/vduse_dev.c b/drivers/vdpa/vdpa_user/vduse_dev.c index 1b833bf0ae37..3df1256eccb4 100644 --- a/drivers/vdpa/vdpa_user/vduse_dev.c +++ b/drivers/vdpa/vdpa_user/vduse_dev.c @@ -1313,6 +1313,35 @@ static struct vduse_dev *vduse_dev_get_from_minor(int minor) return dev; } +int vduse_get_vq_reconnnect(struct vduse_dev *dev, u16 idx) +{ + struct vdpa_reconnect_info *area; + void *addr = (void *)get_zeroed_page(GFP_KERNEL); + + area = &dev->reconnect_info[idx]; + + area->addr = virt_to_phys(addr); + area->vaddr = (unsigned long)addr; + area->size = PAGE_SIZE; + area->index = idx; + + return 0; +} + +int vduse_free_vq_reconnnect(struct vduse_dev *dev, u16 idx) +{ + struct vdpa_reconnect_info *area; + + area = &dev->reconnect_info[idx]; + if ((area->size == PAGE_SIZE) && (area->addr != NULL)) { + free_page(area->vaddr); + area->size = 0; + area->addr = 0; + area->vaddr = 0; + } + + return 0; +} static vm_fault_t vduse_vm_fault(struct vm_fault *vmf) { @@ -1446,6 +1475,10 @@ static int vduse_destroy_dev(char *name) mutex_unlock(&dev->lock); return -EBUSY; } + for (int i = 0; i < dev->vq_num; i++) { + + vduse_free_vq_reconnnect(dev, i); + } dev->connected = true; mutex_unlock(&dev->lock); @@ -1583,6 +1616,8 @@ static int vduse_create_dev(struct vduse_dev_config *config, INIT_WORK(&dev->vqs[i].kick, vduse_vq_kick_work); spin_lock_init(&dev->vqs[i].kick_lock); spin_lock_init(&dev->vqs[i].irq_lock); + + vduse_get_vq_reconnnect(dev, i); } ret = idr_alloc(&vduse_idr, dev, 1, VDUSE_DEV_MAX, GFP_KERNEL); -- 2.34.3