From patchwork Tue Jan 3 10:51:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Boeuf, Sebastien" X-Patchwork-Id: 38372 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp4548347wrt; Tue, 3 Jan 2023 02:53:21 -0800 (PST) X-Google-Smtp-Source: AMrXdXsHM4VOT3I9uNmiIhNhV989V7A/lw64p65++9h/4NqWvzyZvD6XhAXVlo1ufSCHjlxmYtUC X-Received: by 2002:a17:90a:f614:b0:219:672a:42db with SMTP id bw20-20020a17090af61400b00219672a42dbmr53310422pjb.19.1672743201304; Tue, 03 Jan 2023 02:53:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672743201; cv=none; d=google.com; s=arc-20160816; b=dUbu6iz50acaY4Mvca5ngagzN0xCYg/qCqt9Z00Yab2pi2m1aVd9gwJYgK8XBwl8Qf u6uDD6sOSRRz+Hiaq0kVyuVTBHwtjOGT2kxGpOxrVmPcvnHvlXALo5GuOR3VBK5s3+Hu 63z4KiNR+9IubFYre6vzDSCCKuDrIxv4/EeluFQt8rjPioxDG9Z7E6lCmcz+GxXo9tJA D3TtP4Em2RnWIJy0ixgCyT3mMWwOiUtl2+KxPeE3j9MXrZtaQ+a6ojRX6xrFBWLsverE i+iL4XvPI7DbwKJ67CaEIi9bUUJf2TX0sCknQcNiDb42PHcHt+dfS+ZPo2zV/BOQh/al M0lg== 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:cc:to:from :dkim-signature; bh=32OSybmrWfqPTJ78P0BNvontY2SJxNux0lTZ7d3rQww=; b=IC3cCkF8bU5hk/rZFoDtazQXlxFtizpNjp1bnkTpYWBuX31MbwFLs0yFBVqkP0dE+R OpqEdJNlbHcPBa7oQjkWtB6TigXzQB/3QT0yy6zMRUnCVlOed6iv7j6qlSqEiMtgdj5E VVs6gFnKf+EdCYL8mORb3aD3vRfQMNI8lKTh5viyZEL2bGQ9kKzmrxq67TTzrL11Xtau 9rZMGOFNhJh1Vnj/5KvzFC2P509XrZOnwyormj/JZZw1fLMPlTE/gG0Fh+fsjmGv0qP8 rRoMhjMVTR9sGWXKx4vWrySvbge0TI2ZykyI/rzxheSWdWVtkerdGH9ajWOsIvFvGD9j hFIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=ddfmerVj; 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=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k23-20020a63ba17000000b004626957c3c7si33882568pgf.193.2023.01.03.02.53.05; Tue, 03 Jan 2023 02:53:21 -0800 (PST) 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=@intel.com header.s=Intel header.b=ddfmerVj; 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237449AbjACKwO (ORCPT + 99 others); Tue, 3 Jan 2023 05:52:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237350AbjACKvq (ORCPT ); Tue, 3 Jan 2023 05:51:46 -0500 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C67B5FFC for ; Tue, 3 Jan 2023 02:51:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1672743105; x=1704279105; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=lmnHqI3tKK38BSUrN2DgjBvLt72f0TuIKDBVQU/rvhw=; b=ddfmerVjrE7+0suayq7UkX2tHTfDp5ezOWMIB5e1Rye1oVg2/Q7+Uv1M k/Ja6KmucxqmJd1UheCeOHBnDGeG1Al4jXcUBxgZnbmBh2qK8DrpMOzJt YC5hm3WbPhIHXGfQd9lTK2/9Zt69CXnAvIvCzxOqk1ClEzIo6NILmdkbG Y3oNjACCZQKRGFYWIzOavOG90Vl04T0FhHSOo9F3d+/RapiWkA4AxiPa0 nftFlUt6R3ei3B3VSOW1YrqgtdFuzPaa8Z4QA1dE8r/+cPYQRjaoNM3eh +pmFdPXyu07VUMy+Q84pucO2g2bnjVrxdO7ux26102vAsLQnQYh+HnHUX A==; X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="301318478" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="301318478" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:45 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10578"; a="604772731" X-IronPort-AV: E=Sophos;i="5.96,296,1665471600"; d="scan'208";a="604772731" Received: from isobansk-mobl1.ger.corp.intel.com (HELO sboeuf-mobl.home) ([10.252.24.246]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2023 02:51:43 -0800 From: sebastien.boeuf@intel.com To: linux-kernel@vger.kernel.org, virtualization@lists.linux-foundation.org Cc: mst@redhat.com, jasowang@redhat.com, eperezma@redhat.com, sebastien.boeuf@intel.com Subject: [PATCH v6 4/4] vdpa_sim: Implement resume vdpa op Date: Tue, 3 Jan 2023 11:51:08 +0100 Message-Id: <15a4566826033c5dd9a2167e5cfb0ef4d90cea49.1672742878.git.sebastien.boeuf@intel.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,LOTS_OF_MONEY, RCVD_IN_DNSWL_MED,SPF_HELO_PASS,SPF_NONE autolearn=ham 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?1753998375183538014?= X-GMAIL-MSGID: =?utf-8?q?1753998375183538014?= From: Sebastien Boeuf Implement resume operation for vdpa_sim devices, so vhost-vdpa will offer that backend feature and userspace can effectively resume the device. Signed-off-by: Sebastien Boeuf Acked-by: Jason Wang --- drivers/vdpa/vdpa_sim/vdpa_sim.c | 29 +++++++++++++++++++++++++++++ drivers/vdpa/vdpa_sim/vdpa_sim.h | 1 + 2 files changed, 30 insertions(+) diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index b071f0d842fb..756a5db0109c 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -357,6 +357,12 @@ static void vdpasim_kick_vq(struct vdpa_device *vdpa, u16 idx) struct vdpasim *vdpasim = vdpa_to_sim(vdpa); struct vdpasim_virtqueue *vq = &vdpasim->vqs[idx]; + if (!vdpasim->running && + (vdpasim->status & VIRTIO_CONFIG_S_DRIVER_OK)) { + vdpasim->pending_kick = true; + return; + } + if (vq->ready) schedule_work(&vdpasim->work); } @@ -527,6 +533,27 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) return 0; } +static int vdpasim_resume(struct vdpa_device *vdpa) +{ + struct vdpasim *vdpasim = vdpa_to_sim(vdpa); + int i; + + spin_lock(&vdpasim->lock); + vdpasim->running = true; + + if (vdpasim->pending_kick) { + /* Process pending descriptors */ + for (i = 0; i < vdpasim->dev_attr.nvqs; ++i) + vdpasim_kick_vq(vdpa, i); + + vdpasim->pending_kick = false; + } + + spin_unlock(&vdpasim->lock); + + return 0; +} + static size_t vdpasim_get_config_size(struct vdpa_device *vdpa) { struct vdpasim *vdpasim = vdpa_to_sim(vdpa); @@ -717,6 +744,7 @@ static const struct vdpa_config_ops vdpasim_config_ops = { .set_status = vdpasim_set_status, .reset = vdpasim_reset, .suspend = vdpasim_suspend, + .resume = vdpasim_resume, .get_config_size = vdpasim_get_config_size, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, @@ -750,6 +778,7 @@ static const struct vdpa_config_ops vdpasim_batch_config_ops = { .set_status = vdpasim_set_status, .reset = vdpasim_reset, .suspend = vdpasim_suspend, + .resume = vdpasim_resume, .get_config_size = vdpasim_get_config_size, .get_config = vdpasim_get_config, .set_config = vdpasim_set_config, diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.h b/drivers/vdpa/vdpa_sim/vdpa_sim.h index 0e78737dcc16..a745605589e2 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.h +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.h @@ -67,6 +67,7 @@ struct vdpasim { u64 features; u32 groups; bool running; + bool pending_kick; /* spinlock to synchronize iommu table */ spinlock_t iommu_lock; };