From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 30ABC35BDCE for ; Wed, 19 Nov 2025 12:30:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763555409; cv=none; b=Bth6SdqM/Dt8DYN1TfRjjK918J26MZ9VDtfYWFrhdPOCUUbf2jniY5IjxnLvA5js4yiObfFCm+FToIeCYRTBzEQLm8YVZ5/G/+fBR1ktGbn6YINcpoulaw+N3AO3IPnrrYwbPnoUD/nSGnE8i1DhUnMwAuI2+vjgURS/Ta319Bo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763555409; c=relaxed/simple; bh=B9Hd45HezP2oyNR1nvgyt+XG2H3dwGTxC4mYxN9sC/I=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=OBRrj6UT7EELFfhK8agER32iIRGVMR4aLtB3DNJLi6Gil9yEsWA0W0wKPcdHc1WRXia60K1HpSOUOUgfs0vMyQ//42lnwl+TreINq/54jpHEegSk/vkjVvKPlfGJDzxrstKBr4L4B6yqCaONzS2yBNSVPH8lJJaFsY45Xewb0Io= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=EBgVHF/l; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=ndoRQFkD; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="EBgVHF/l"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="ndoRQFkD" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763555405; 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=18z3Rp/qSfSuoAWshJjuMwA1IwB2JmsxvWb+k0pXveI=; b=EBgVHF/lzG/tmd8Zk8PMk6B3AsdeIcDEKwMOE+FlsJtUzwUxXyofMcNWJM8fjSK7R/mW2w 47PmTjGSc9bsVG5HqBJyLQ4wg8OlLVoQfDPq66wRF/oyUFfXHhYelYVB8Fmxbz6m0RJSnn Cm1E3OxlQiGQroTCNJ8ZvvnmO4XPE90= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-qlms-Q8SPm-GHeHvlXc5sA-1; Wed, 19 Nov 2025 07:30:04 -0500 X-MC-Unique: qlms-Q8SPm-GHeHvlXc5sA-1 X-Mimecast-MFC-AGG-ID: qlms-Q8SPm-GHeHvlXc5sA_1763555403 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-477563e531cso61928565e9.1 for ; Wed, 19 Nov 2025 04:30:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1763555403; x=1764160203; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=18z3Rp/qSfSuoAWshJjuMwA1IwB2JmsxvWb+k0pXveI=; b=ndoRQFkDjGSatetfFf3/ZDNPjkI6xFU+lHDpEeFzXZKONJSeGW4+qijP774GanV9oN au7MW1/3e1wJNZOcJ4BxjIvNlaYl1ZiQ0VbywrGf7qjmmXDFzfTIy/R1PeM74sWDlCl+ Dq/mV6cUt6XLF4MaTJMnMZxf+uSormTWBRcHhYl3p3IjDGTIYi4xJlqZx4leyD7/2ZOi 98g1UPu4ypbLt+ZJFyCozR0geO/qeY3G5767CK9BvzhJ7WUXiYb3jdeUHWpCuR9LvKsz Lb75rTALVw3R9Sfp8Kg6BQgB0HHRhEoHCbnZLlJBYqA0qklaNILBGkUoRyUB0PvBLtBf CNmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1763555403; x=1764160203; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=18z3Rp/qSfSuoAWshJjuMwA1IwB2JmsxvWb+k0pXveI=; b=mj4AmMmHjuQwvTiSm1I1lBnf5n9g4CzWVKOJM5NzmeQFJyfCyoRfsbfzHzVscFRwHr +40UuFVhzHc47zSn4HIsBwqwfut3f8XR53aU5k4GNx9v2NXtYrtMBM9FpaSJrMbGVGdC ZTKlFYS4mmkABh3WljjrcvnNEn4gdTFDjpqKAkkKtOnVX0Np9xYxnnpHbdedlSL3gu2H zbfJomsjD+W75rZHhh7ein9gm6Bk6/QMeRCY8Rm9ALZw5gacvkalqgkHl3skqWPHdyxp gai7z6LBn+/NtwR9zXRLPrbBKgC5V2MUxb2kfv5gzFC2UjPySh5/NvF4tLmZJGY+sk8W n58g== X-Forwarded-Encrypted: i=1; AJvYcCWQxlUIvr3N6hn7YVoUfubL+rODSjyDHX7P4FFbOlWPEGrp4j8ufl5XuG1WDruud6xGmDV7b8jtuPa42yQ=@vger.kernel.org X-Gm-Message-State: AOJu0Ywcc6+PYB0f1z9SXkh3D9MwytMYRHQ5zT6zKfP4mppagsZrmKz+ 84ffptsEHcs+Ygiq+emLeWM86oQ/OVd1iPDNV/nX9XIi1+JpbzLc8wBkh8N6YFOaCfT9btMAX+w Bt/JuRhB6hSNF3OwYq3yfOQLzFnQucxAUvrVrn2AOYbSiV5Be+FI9k0t/rif3L7vFMA== X-Gm-Gg: ASbGncsXxoy6lB+cuhW2bn+R0+exnuJq5S8HBTA0sduTl5iYJPVFUO5hRkR2IDSI9lw 2ovAI480b05kwFoXouZY73KTZ0rBVz2pq7dsXU++B2d/xemCWyupIXbuxoHNc+bS0P3xner6ZmT rQsu5l7gX1XLXbYlwZ+HSqh7R+KNT3cVG6VQu6gE0Yypt0BqB86Z5eCSOYb3PXtIOvULqnv//ca tz2iiOxLiwFcGQrqM4chNdu/VTLwIotKi5h6Ci1XS4cL9qemEn6ZtIIEvHFJmZhkfjKWL6SmOzn AtRw+mpEsjHn30I3vsQccX6qSdmqDOOj0BPiyGjFgpXx/3wa8fzAjMGAzLmXEWaVypwH7mVOYyO XzDQOWPiHIPtYYtwrzw+YRJUbLbUHCA== X-Received: by 2002:a05:600c:4594:b0:477:214f:bd95 with SMTP id 5b1f17b1804b1-4778fe9b281mr195112525e9.23.1763555402929; Wed, 19 Nov 2025 04:30:02 -0800 (PST) X-Google-Smtp-Source: AGHT+IFxlqO5Fv/NfwlSqVNAM5or6LYkWN8dNS3H2JehIcMpwsjRD2voPi/TWaWzWNKn0QKk1a/cKw== X-Received: by 2002:a05:600c:4594:b0:477:214f:bd95 with SMTP id 5b1f17b1804b1-4778fe9b281mr195111965e9.23.1763555402467; Wed, 19 Nov 2025 04:30:02 -0800 (PST) Received: from redhat.com (IGLD-80-230-39-63.inter.net.il. [80.230.39.63]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-477b10173a3sm43844595e9.5.2025.11.19.04.30.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Nov 2025 04:30:01 -0800 (PST) Date: Wed, 19 Nov 2025 07:29:59 -0500 From: "Michael S. Tsirkin" To: Eugenio Perez Martin Cc: Jason Wang , Laurent Vivier , virtualization@lists.linux.dev, Maxime Coquelin , Cindy Lu , linux-kernel@vger.kernel.org, Yongji Xie , Xuan Zhuo , Stefano Garzarella Subject: Re: [PATCH v9 5/6] vduse: add vq group asid support Message-ID: <20251119072555-mutt-send-email-mst@kernel.org> References: <20251113115558.1277981-1-eperezma@redhat.com> <20251113115558.1277981-6-eperezma@redhat.com> <20251119042923-mutt-send-email-mst@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Wed, Nov 19, 2025 at 11:38:32AM +0100, Eugenio Perez Martin wrote: > On Wed, Nov 19, 2025 at 10:32 AM Michael S. Tsirkin wrote: > > > > On Wed, Nov 19, 2025 at 10:26:43AM +0100, Eugenio Perez Martin wrote: > > > > But this is not the logic that is > > > > implemented in this patch as there's no synchronize_rcu() in the > > > > vduse_set_group_asid_nomsg(). > > > > > > We only set the pointer on the writer's side, we do nothing like > > > freeing resources. Should we set the pointer before or after > > > syncrhonize_rcu()? > > > > synchronize_rcu is called after writer makes it's changes. > > > > > What do we need to do on the other side of > > > syncrhonize_rcu()? > > > > Presumably, return so the caller knows the as has been updated. > > > > I'm happy to add the syncrhonize_rcu() just in case, but the caller of > vduse_set_group_asid_nomsg does not need to know that the reader has > been updated. > > The first caller is vduse_dev_reset which has its own way to avoid > being called while vqs are being processed. In particular, it reset > their addresses which is way more dangerous. I could call it with > dev->rwsem down though. > > The second one is set_group_asid vdpa callback which is called from > the ioctl itself. This one for sure needs to know that after ioctl completed the new AS is in use. > Moreover, rcu_assign_pointer is WRITE_ONCE by itself so we know all > the readers will get the new value after it. No we don't. The words "after it" do not have a meaning on an SMP system. The only way to know that another CPU sees a value is to synchronize with it. > So what's the value of > explicitly waiting for all the readers to finalize their DMA operation? Read Documentation/memory-barriers.txt If still unclear, read it again )) > I'd understand if we need to do modifications or memory management in > the now unused ASID, but that's not the case here. > > > However, user-triggerable synchronize_rcu() is almost always a bug. > > > > If that's what is going on, you want srcu. > > > > I did not know about it, thanks! but I think all the code that can > sleep is out of the RCU critical sections now, isn't it? what I tried to say is that if triggering synchronize_rcu from userspace is a problem, srcu is one solution.