Message ID | 1704919215-91319-11-git-send-email-steven.sistare@oracle.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-22768-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1045231dyi; Wed, 10 Jan 2024 12:46:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IG88utDO8JD2R1uedZWWvhZxXm8NLTr/hHrMwIc2/qvk1AeOfICkVwygUmEyWqGi298IYqy X-Received: by 2002:a17:906:198f:b0:a26:f1d5:fb4c with SMTP id g15-20020a170906198f00b00a26f1d5fb4cmr17575ejd.295.1704919581926; Wed, 10 Jan 2024 12:46:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704919581; cv=none; d=google.com; s=arc-20160816; b=s1Ies6suMqvCfPVQIO/sh0TEEtbsBN3w64oJzSibajPeAtGNY2iZNNys05M5+NVDQH yTHOZ8Im9E3nIRMRvMP1xVPlsVG7luHIAZw/pYLvfmMd8WbZGTNuCL6ZKkXTGowAW8pp ZxU6EvlYFVP0EB34YO5uJJaInjkB0+yLyjm1T7wB2NilMN1q06l6jkk2wr1A14+I4/1e nfzPTomla+JVRXfOuL/WcFwqIPBJogMOqR5xtGe8saKR5JE58JbGt0x2cjd3+A5ZAelq 1VM0BQlxbSv1OpSZyxOUXs/RUPcdCfBH8CNr3fD4UUibRP9TXvCtQtlYF30l48UtLA1/ eTAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=NFZx/EFKZOPMSB3OaPzQiVb/lgOe0vt9g+rSbf9Taic=; fh=NLOUc4UpZ/0A9JrieYT9bxhjFpxay5qeZXON7PgxqoM=; b=i52mp6GgBH0UfOiXFa0jQfa9V1NWMND3pUICiZbTfowH6oZRLWna4W9IHlFDFjP1eZ 0PGdXmV5ej1Mja0xauWEk6RBO+qvYf2rM3ctw0C1WhNPHRbu8ZL+B+Zw29EYQ1Dmui4b mjjwjBlJ7eyY5JzEXEGeB7tQBSBsKCSMooKLlZmUN8pzJ1y5IbVv2KM47/SgRTzjZhtU sZkeykIR1Ekx9ryld6G8ML/8i3HI6EJu5XTYKTAowbePsLJdX9z3k96RlO7NAE/TRYJn 78fCuNGzdv2nL09LhwJpcdLlqE9DPsjXMDuXEK8mh6Nm55rglEuW5JFJzxySEBQr8MnW 6Amw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=GXDavQHm; spf=pass (google.com: domain of linux-kernel+bounces-22768-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id gr3-20020a170906e2c300b00a2a4a9e6be9si1992248ejb.67.2024.01.10.12.46.21 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 12:46:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-22768-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-11-20 header.b=GXDavQHm; spf=pass (google.com: domain of linux-kernel+bounces-22768-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-22768-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 98B3F1F23AEA for <ouuuleilei@gmail.com>; Wed, 10 Jan 2024 20:46:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F66957882; Wed, 10 Jan 2024 20:40:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="GXDavQHm" Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2567357339 for <linux-kernel@vger.kernel.org>; Wed, 10 Jan 2024 20:40:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 40AJfmVQ028156; Wed, 10 Jan 2024 20:40:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2023-11-20; bh=NFZx/EFKZOPMSB3OaPzQiVb/lgOe0vt9g+rSbf9Taic=; b=GXDavQHmS5tUjLInShR585JNceUqkw1Lcofpv0QDo4qb/0J+I24z9u6xaAnHQQ5COOHK xupM/kJoP5+xpbhsc4+BpaarrutY+fbyD3h8TzkJ9/xeS+RF/YM5Tr6dr8IC2mKeGpe0 aumsDcU3D3JWqPq/VVG7mDXZrgQsJ8TckBpNVlkVoV3Cg3BXUqCXmIf+2m0tzkP9y02k ssXh82bebZ2Mj7K3bwfoLYzpOYod6dRs0sjOd5DXdEA2eqyCejWnUWKxEvO4Kae/eN+u NjS7xZaIMbblmX76WAZO9miDAttcQYJAxP9xoMV/uCBTq16DzlmkG6PbLMNwRjBSQGAm dA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3vj1m404ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:26 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 40AIvv0U030295; Wed, 10 Jan 2024 20:40:25 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3vfutp5xcd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 10 Jan 2024 20:40:25 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 40AKeGrj005067; Wed, 10 Jan 2024 20:40:24 GMT Received: from ca-dev63.us.oracle.com (ca-dev63.us.oracle.com [10.211.8.221]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3vfutp5x5e-11; Wed, 10 Jan 2024 20:40:24 +0000 From: Steve Sistare <steven.sistare@oracle.com> To: virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org Cc: "Michael S. Tsirkin" <mst@redhat.com>, Jason Wang <jasowang@redhat.com>, Si-Wei Liu <si-wei.liu@oracle.com>, Eugenio Perez Martin <eperezma@redhat.com>, Xuan Zhuo <xuanzhuo@linux.alibaba.com>, Dragos Tatulea <dtatulea@nvidia.com>, Eli Cohen <elic@nvidia.com>, Xie Yongji <xieyongji@bytedance.com>, Steve Sistare <steven.sistare@oracle.com> Subject: [RFC V1 10/13] vdpa_sim: flush workers on suspend Date: Wed, 10 Jan 2024 12:40:12 -0800 Message-Id: <1704919215-91319-11-git-send-email-steven.sistare@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> References: <1704919215-91319-1-git-send-email-steven.sistare@oracle.com> X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-01-10_10,2024-01-10_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 bulkscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxlogscore=999 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311290000 definitions=main-2401100163 X-Proofpoint-ORIG-GUID: R2OpFmtsJ-lX7DSIEv1LxOHwtgQ4LfMP X-Proofpoint-GUID: R2OpFmtsJ-lX7DSIEv1LxOHwtgQ4LfMP Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787737755701676295 X-GMAIL-MSGID: 1787737755701676295 |
Series |
vdpa live update
|
|
Commit Message
Steven Sistare
Jan. 10, 2024, 8:40 p.m. UTC
To pass ownership of a live vdpa device to a new process, the user
suspends the device, calls VHOST_NEW_OWNER to change the mm, and calls
VHOST_IOTLB_REMAP to change the user virtual addresses to match the new
mm. Flush workers in suspend to guarantee that no worker sees the new
mm and old VA in between.
Signed-off-by: Steve Sistare <steven.sistare@oracle.com>
---
drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
On Wed, Jan 10, 2024 at 9:40 PM Steve Sistare <steven.sistare@oracle.com> wrote: > > To pass ownership of a live vdpa device to a new process, the user > suspends the device, calls VHOST_NEW_OWNER to change the mm, and calls > VHOST_IOTLB_REMAP to change the user virtual addresses to match the new > mm. Flush workers in suspend to guarantee that no worker sees the new > mm and old VA in between. > The worker should already be stopped by the end of the suspend ioctl, so maybe we can consider this a fix? > Signed-off-by: Steve Sistare <steven.sistare@oracle.com> > --- > drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c > index 6304cb0b4770..8734834983cb 100644 > --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c > +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c > @@ -74,6 +74,17 @@ static void vdpasim_worker_change_mm_sync(struct vdpasim *vdpasim, > kthread_flush_work(work); > } > > +static void flush_work_fn(struct kthread_work *work) {} > + > +static void vdpasim_flush_work(struct vdpasim *vdpasim) > +{ > + struct kthread_work work; > + > + kthread_init_work(&work, flush_work_fn); > + kthread_queue_work(vdpasim->worker, &work); > + kthread_flush_work(&work); Wouldn't it be better to cancel the work with kthread_cancel_work_sync here? > +} > + > static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa) > { > return container_of(vdpa, struct vdpasim, vdpa); > @@ -512,6 +523,8 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) > vdpasim->running = false; > mutex_unlock(&vdpasim->mutex); > > + vdpasim_flush_work(vdpasim); > + > return 0; > } > > -- > 2.39.3 >
On 1/16/2024 1:57 PM, Eugenio Perez Martin wrote: > On Wed, Jan 10, 2024 at 9:40 PM Steve Sistare <steven.sistare@oracle.com> wrote: >> >> To pass ownership of a live vdpa device to a new process, the user >> suspends the device, calls VHOST_NEW_OWNER to change the mm, and calls >> VHOST_IOTLB_REMAP to change the user virtual addresses to match the new >> mm. Flush workers in suspend to guarantee that no worker sees the new >> mm and old VA in between. > > The worker should already be stopped by the end of the suspend ioctl, > so maybe we can consider this a fix? Do you mean: the current behavior is a bug, independently of my new use case, so I should submit this patch as a separate bug fix? If yes, then will do. >> Signed-off-by: Steve Sistare <steven.sistare@oracle.com> >> --- >> drivers/vdpa/vdpa_sim/vdpa_sim.c | 13 +++++++++++++ >> 1 file changed, 13 insertions(+) >> >> diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c >> index 6304cb0b4770..8734834983cb 100644 >> --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c >> +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c >> @@ -74,6 +74,17 @@ static void vdpasim_worker_change_mm_sync(struct vdpasim *vdpasim, >> kthread_flush_work(work); >> } >> >> +static void flush_work_fn(struct kthread_work *work) {} >> + >> +static void vdpasim_flush_work(struct vdpasim *vdpasim) >> +{ >> + struct kthread_work work; >> + >> + kthread_init_work(&work, flush_work_fn); >> + kthread_queue_work(vdpasim->worker, &work); >> + kthread_flush_work(&work); > > Wouldn't it be better to cancel the work with kthread_cancel_work_sync here? I believe that does not guarantee that currently executing work completes: static bool __kthread_cancel_work_sync() if (worker->current_work != work) goto out_fast; - Steve >> +} >> + >> static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa) >> { >> return container_of(vdpa, struct vdpasim, vdpa); >> @@ -512,6 +523,8 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) >> vdpasim->running = false; >> mutex_unlock(&vdpasim->mutex); >> >> + vdpasim_flush_work(vdpasim); >> + >> return 0; >> } >> >> -- >> 2.39.3 >> >
diff --git a/drivers/vdpa/vdpa_sim/vdpa_sim.c b/drivers/vdpa/vdpa_sim/vdpa_sim.c index 6304cb0b4770..8734834983cb 100644 --- a/drivers/vdpa/vdpa_sim/vdpa_sim.c +++ b/drivers/vdpa/vdpa_sim/vdpa_sim.c @@ -74,6 +74,17 @@ static void vdpasim_worker_change_mm_sync(struct vdpasim *vdpasim, kthread_flush_work(work); } +static void flush_work_fn(struct kthread_work *work) {} + +static void vdpasim_flush_work(struct vdpasim *vdpasim) +{ + struct kthread_work work; + + kthread_init_work(&work, flush_work_fn); + kthread_queue_work(vdpasim->worker, &work); + kthread_flush_work(&work); +} + static struct vdpasim *vdpa_to_sim(struct vdpa_device *vdpa) { return container_of(vdpa, struct vdpasim, vdpa); @@ -512,6 +523,8 @@ static int vdpasim_suspend(struct vdpa_device *vdpa) vdpasim->running = false; mutex_unlock(&vdpasim->mutex); + vdpasim_flush_work(vdpasim); + return 0; }