From mboxrd@z Thu Jan 1 00:00:00 1970 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=-17.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham 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 5800AC47089 for ; Thu, 27 May 2021 18:48:57 +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 196B7613AF for ; Thu, 27 May 2021 18:48:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 196B7613AF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org 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.133648.249034 (Exim 4.92) (envelope-from ) id 1lmL3m-0004ws-3V; Thu, 27 May 2021 18:48:46 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 133648.249034; Thu, 27 May 2021 18:48:46 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmL3l-0004wl-Vu; Thu, 27 May 2021 18:48:45 +0000 Received: by outflank-mailman (input) for mailman id 133648; Thu, 27 May 2021 18:48:45 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmL3l-0004wf-EP for xen-devel@lists.xenproject.org; Thu, 27 May 2021 18:48:45 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1lmL3j-0006JL-RI; Thu, 27 May 2021 18:48:43 +0000 Received: from [54.239.6.186] (helo=a483e7b01a66.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lmL3j-0006MH-LB; Thu, 27 May 2021 18:48:43 +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" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:In-Reply-To: MIME-Version:Date:Message-ID:From:References:Cc:To:Subject; bh=gdFLE1hfABuvxFWtXsBOMA7TF9HSzyLSeS6Rr/mUTrU=; b=OnjK7VFthuonyzTUJ64fDUnz7g 6hXEWrhzCjiUTMcuc+rYyjXEQz558Xh5ckN3KZ+Qbl2YNB3Ux7eUvyaHqXwUKuVCsmH5n2PQmNUH2 gVwb0kGEah40y+OK/6hiKQ1dBLHKHeoL4OwfXzew3s6QTIBwT37WROPyspK06xj1fVtk=; Subject: Re: [PATCH v6 1/3] evtchn: slightly defer lock acquire where possible To: Jan Beulich , "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Wei Liu , Stefano Stabellini , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= References: <01bbf3d4-ca6a-e837-91fe-b34aa014564c@suse.com> <5939858e-1c7c-5658-bc2d-0c9024c74040@suse.com> From: Julien Grall Message-ID: <938eb888-ec15-feb1-19f7-b90dfee822ae@xen.org> Date: Thu, 27 May 2021 19:48:41 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.2 MIME-Version: 1.0 In-Reply-To: <5939858e-1c7c-5658-bc2d-0c9024c74040@suse.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Hi Jan, On 27/05/2021 12:28, Jan Beulich wrote: > port_is_valid() and evtchn_from_port() are fine to use without holding > any locks. Accordingly acquire the per-domain lock slightly later in > evtchn_close() and evtchn_bind_vcpu(). So I agree that port_is_valid() and evtchn_from_port() are fine to use without holding any locks in evtchn_bind_vcpu(). However, this is misleading to say there is no problem with evtchn_close(). evtchn_close() can be called with current != d and therefore, there is a risk that port_is_valid() may be valid and then invalid because d->valid_evtchns is decremented in evtchn_destroy(). Thankfully the memory is still there. So the current code is okayish and I could reluctantly accept this behavior to be spread. However, I don't think this should be left uncommented in both the code (maybe on top of port_is_valid()?) and the commit message. > > Signed-off-by: Jan Beulich > --- > v6: Re-base for re-ordering / shrinking of series. > v4: New. > > --- a/xen/common/event_channel.c > +++ b/xen/common/event_channel.c > @@ -606,17 +606,14 @@ int evtchn_close(struct domain *d1, int > int port2; > long rc = 0; > > - again: > - spin_lock(&d1->event_lock); > - > if ( !port_is_valid(d1, port1) ) > - { > - rc = -EINVAL; > - goto out; > - } > + return -EINVAL; > > chn1 = evtchn_from_port(d1, port1); > > + again: > + spin_lock(&d1->event_lock); > + > /* Guest cannot close a Xen-attached event channel. */ > if ( unlikely(consumer_is_xen(chn1)) && guest ) > { > @@ -1041,16 +1038,13 @@ long evtchn_bind_vcpu(unsigned int port, > if ( (v = domain_vcpu(d, vcpu_id)) == NULL ) > return -ENOENT; > > - spin_lock(&d->event_lock); > - > if ( !port_is_valid(d, port) ) > - { > - rc = -EINVAL; > - goto out; > - } > + return -EINVAL; > > chn = evtchn_from_port(d, port); > > + spin_lock(&d->event_lock); > + > /* Guest cannot re-bind a Xen-attached event channel. */ > if ( unlikely(consumer_is_xen(chn)) ) > { > Cheers, -- Julien Grall