Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CABA0C4727C for ; Tue, 29 Sep 2020 13:37:58 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 45BE5207C4 for ; Tue, 29 Sep 2020 13:37:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="l3/axlC6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 45BE5207C4 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.206.473 (Exim 4.92) (envelope-from ) id 1kNFov-0005zH-JK; Tue, 29 Sep 2020 13:37:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 206.473; Tue, 29 Sep 2020 13:37:29 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kNFov-0005zA-FJ; Tue, 29 Sep 2020 13:37:29 +0000 Received: by outflank-mailman (input) for mailman id 206; Tue, 29 Sep 2020 13:37:28 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kNFou-0005z5-7h for xen-devel@lists.xenproject.org; Tue, 29 Sep 2020 13:37:28 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 675591d0-d1df-43f5-9661-013716a671f5; Tue, 29 Sep 2020 13:37:27 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 590F3ACC8; Tue, 29 Sep 2020 13:37:26 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kNFou-0005z5-7h for xen-devel@lists.xenproject.org; Tue, 29 Sep 2020 13:37:28 +0000 X-Inumbo-ID: 675591d0-d1df-43f5-9661-013716a671f5 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 675591d0-d1df-43f5-9661-013716a671f5; Tue, 29 Sep 2020 13:37:27 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1601386646; 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=3Jb3Rpf3DttGcxJjLzSEEpO5wsWj9vVVnrq53PDKDhI=; b=l3/axlC6kgVRM6I33P2fTwqTVo/l0SucWvhNItb9nV/+O8kHYROEzgggxVY3Aw5SGUACu8 k07iLhMP17geM/d8jIgcLKJJ1bjeNR3CPnCtfx5NyMacMhY/Eqg0wk9om39uPh2SgaJ6cU MkOVVX8btBQKX0IF7lPJorX8HXqixIk= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 590F3ACC8; Tue, 29 Sep 2020 13:37:26 +0000 (UTC) Subject: Re: [PATCH 11/12] evtchn: convert vIRQ lock to an r/w one To: Julien Grall Cc: "xen-devel@lists.xenproject.org" , Andrew Cooper , George Dunlap , Ian Jackson , Wei Liu , Stefano Stabellini References: <0d5ffc89-4b04-3e06-e950-f0cb171c7419@suse.com> <6e529147-2a76-bc28-ac16-21fc9a2c8f03@suse.com> <56faf769-d305-22d3-c3fe-2f9d767f0f07@xen.org> From: Jan Beulich Message-ID: <60490a6c-593b-7aed-5e83-b0418500eed2@suse.com> Date: Tue, 29 Sep 2020 15:37:24 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <56faf769-d305-22d3-c3fe-2f9d767f0f07@xen.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 29.09.2020 15:03, Julien Grall wrote: > On 28/09/2020 12:02, Jan Beulich wrote: >> There's no need to serialize all sending of vIRQ-s; all that's needed >> is serialization against the closing of the respective event channels >> (by means of a barrier). To facilitate the conversion, introduce a new >> rw_barrier(). > > Looking at the code below, all the spin_lock() have been replaced by a > read_lock_*(). This is a bit surprising, It is, I agree, but that's what it ends up being. It is my understanding that the lock really only exists for the purpose of the barrier in evtchn_close(). >> --- a/xen/common/spinlock.c >> +++ b/xen/common/spinlock.c >> @@ -2,7 +2,7 @@ >> #include >> #include >> #include >> -#include >> +#include > > I would prefer if keep including as the fact > include it is merely an implementation details. Can do, sure. >> @@ -334,6 +334,12 @@ void _spin_unlock_recursive(spinlock_t * >> } >> } >> >> +void _rw_barrier(rwlock_t *lock) >> +{ >> + check_barrier(&lock->lock.debug); >> + do { smp_mb(); } while ( _rw_is_locked(lock) ); >> +} > > Why do you need to call smp_mb() at each loop? Would not it be > sufficient to write something similar to spin_barrier(). I.e: > > smp_mb(); > while ( _rw_is_locked(lock) ) > cpu_relax(); > smp_mb(); Yes, this looks to be possible. Both for this and the question below it may be relevant to know that this patch pre-dates the conversion to ticket locks by quite a bit. Hence the construct above resembles the _spin_barrier() back at the time. > But I wonder if there is a risk with either implementation for > _rw_is_locked() to always return true and therefore never end. > > Let say we receive an interrupt, by the time it is handled, the > read/lock may have been taken again. With non-ticket locks I would say there was the same issue. But yes, ... > spin_barrier() seems to handle this situation fine because it just wait > for the head to change. I don't think we can do the same here... > > I am thinking that it may be easier to hold the write lock when doing > the update. ... perhaps this is indeed better. I have to admit that I never fully understood the benefit of using spin_barrier() in this code (as opposed to the use in evtchn_destroy()). Jan