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.6 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 B47DDC4363D for ; Fri, 2 Oct 2020 06:12:42 +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 54B7C206DC for ; Fri, 2 Oct 2020 06:12:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="ipE3kbU7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54B7C206DC 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.1680.5084 (Exim 4.92) (envelope-from ) id 1kOEIt-0003Tb-1m; Fri, 02 Oct 2020 06:12:27 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 1680.5084; Fri, 02 Oct 2020 06:12:27 +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 1kOEIs-0003TU-UE; Fri, 02 Oct 2020 06:12:26 +0000 Received: by outflank-mailman (input) for mailman id 1680; Fri, 02 Oct 2020 06:12:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kOEIr-0003TP-Bp for xen-devel@lists.xenproject.org; Fri, 02 Oct 2020 06:12:25 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 998311f9-3f0f-47fe-813d-7f903fea7e5b; Fri, 02 Oct 2020 06:12:24 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 502B8B312; Fri, 2 Oct 2020 06:12:23 +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 1kOEIr-0003TP-Bp for xen-devel@lists.xenproject.org; Fri, 02 Oct 2020 06:12:25 +0000 X-Inumbo-ID: 998311f9-3f0f-47fe-813d-7f903fea7e5b Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 998311f9-3f0f-47fe-813d-7f903fea7e5b; Fri, 02 Oct 2020 06:12:24 +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=1601619143; 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=8Hw7ZlxAQw/pdvyez1KAKHCb7RLR/cvQxCiac0pD7MM=; b=ipE3kbU7FzZQkYcOYhQwb3h8S7qNCnkQG7dYE7Z4PJyKo4KtLkwcdJ/tPpNKFvCsSS2AYl pydYiuKT5NGONK3PK+rMk9JgZAG4zWjhunJX21rb3dW+3Lyoz3YUYYMnToUl/YBhk5MH72 IdBoLprPvG9Mwx/ix8G1oGfY8cp/P60= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 502B8B312; Fri, 2 Oct 2020 06:12:23 +0000 (UTC) Subject: Re: [PATCH 11/12] evtchn: convert vIRQ lock to an r/w one To: Julien Grall Cc: paul@xen.org, 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> <004b01d696ff$76873e50$6395baf0$@xen.org> <92d2714b-d762-2f15-086f-58257e3336a8@suse.com> <006401d69707$062a5090$127ef1b0$@xen.org> <3626d65c-bd5d-f65e-61ca-451110761258@suse.com> From: Jan Beulich Message-ID: <60f2ae90-160f-d7fe-9d5f-f9cd4651a93c@suse.com> Date: Fri, 2 Oct 2020 08:12:18 +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: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 01.10.2020 18:21, Julien Grall wrote: > On 30/09/2020 11:16, Jan Beulich wrote: >> On 30.09.2020 10:52, Paul Durrant wrote: >>> Looking again, given that both send_guest_vcpu_virq() and >>> send_guest_global_virq() (rightly) hold the evtchn lock before >>> calling evtchn_port_set_pending() I think you could do away with >>> the virq lock by adding checks in those functions to verify >>> evtchn->state == ECS_VIRQ and u.virq == virq after having >>> acquired the channel lock but before calling >>> evtchn_port_set_pending(). >> >> I don't think so: The adjustment of v->virq_to_evtchn[] in >> evtchn_close() would then happen with just the domain's event >> lock held, which the sending paths don't use at all. The per- >> channel lock gets acquired in evtchn_close() a bit later only >> (and this lock can't possibly protect per-vCPU state). >> >> In fact I'm now getting puzzled by evtchn_bind_virq() updating >> this array with (just) the per-domain lock held. Since it's >> the last thing in the function, there's technically no strict >> need for acquiring the vIRQ lock, > > Well, we at least need to prevent the compiler to tear the store/load. > If we don't use a lock, then we would should use ACCESS_ONCE() or > {read,write}_atomic() for all the usage. > >> but holding the event lock >> definitely doesn't help. > > It helps because spin_unlock() and write_unlock() use the same barrier > (arch_lock_release_barrier()). So ... I'm having trouble making this part of your reply fit ... >> All that looks to be needed is the >> barrier implied from write_unlock(). > > No barrier should be necessary. Although, I would suggest to add a > comment explaining it. ... this. If we moved the update of v->virq_to_evtchn[] out of the locked region (as the lock doesn't protect anything anymore at that point), I think a barrier would need adding, such that the sending paths will observe the update by the time evtchn_bind_virq() returns (and hence sending of a respective vIRQ event can legitimately be expected to actually work). Or did you possibly just misunderstand what I wrote before? By putting in question the utility of holding the event lock, I implied the write could be moved out of the locked region ... Jan