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 95EC6C433E0 for ; Wed, 27 Jan 2021 07:39:39 +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 2DBFE20663 for ; Wed, 27 Jan 2021 07:39:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2DBFE20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine 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.75766.136492 (Exim 4.92) (envelope-from ) id 1l4fQA-00014c-Ue; Wed, 27 Jan 2021 07:39:22 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 75766.136492; Wed, 27 Jan 2021 07:39:22 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4fQA-00014V-RI; Wed, 27 Jan 2021 07:39:22 +0000 Received: by outflank-mailman (input) for mailman id 75766; Wed, 27 Jan 2021 07:39:20 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l4fQ8-00014Q-Rz for xen-devel@lists.xenproject.org; Wed, 27 Jan 2021 07:39:20 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9cecfee7-ec32-4ecc-bf79-275e71e7401a; Wed, 27 Jan 2021 07:39:19 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 901E8AD7F; Wed, 27 Jan 2021 07:39:18 +0000 (UTC) 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" X-Inumbo-ID: 9cecfee7-ec32-4ecc-bf79-275e71e7401a 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=1611733158; h=from:from:reply-to: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=/BG6mb1+fxHiWJbMqA+mfmVM5ygqUlDR+zs32eBDPnU=; b=b2wxWaj+QkaQfzhZhstPwq/hp1xGggvDJviSGXp/V4mkydHGztPw0omsD046a0zDhhra6n VwuDLsTEo0t+/EeTc9zvS9NS8VgOVwzG1ttZdBo+XuT4vEXP4MS87OkcVeye32Aw1XXJ7p TDr7WrO854JlkugQyEh+GX4xyHjehAc= Subject: Re: [PATCH v4 01/10] evtchn: use per-channel lock where possible To: Julien Grall Cc: Andrew Cooper , George Dunlap , Ian Jackson , Wei Liu , Stefano Stabellini , "xen-devel@lists.xenproject.org" References: <3c393170-09f9-6d31-c227-b599f8769e35@xen.org> <69e94f3e-5fca-e77e-0b85-56057e7fce19@suse.com> From: Jan Beulich Message-ID: Date: Wed, 27 Jan 2021 08:39:11 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit On 11.01.2021 12:06, Julien Grall wrote: > On 11/01/2021 10:14, Jan Beulich wrote: >> On 08.01.2021 21:32, Julien Grall wrote: >>> On 05/01/2021 13:09, Jan Beulich wrote: >>>> Neither evtchn_status() nor domain_dump_evtchn_info() nor >>>> flask_get_peer_sid() need to hold the per-domain lock - they all only >>>> read a single channel's state (at a time, in the dump case). >>>> >>>> Signed-off-by: Jan Beulich >>>> --- >>>> v4: New. >>>> >>>> --- a/xen/common/event_channel.c >>>> +++ b/xen/common/event_channel.c >>>> @@ -968,15 +968,16 @@ int evtchn_status(evtchn_status_t *statu >>>> if ( d == NULL ) >>>> return -ESRCH; >>>> >>>> - spin_lock(&d->event_lock); >>>> - >>>> if ( !port_is_valid(d, port) ) >>> >>> There is one issue that is now becoming more apparent. To be clear, the >>> problem is not in this patch, but I think it is the best place to >>> discuss it as d->event_lock may be part of the solution. >>> >>> After XSA-344, evtchn_destroy() will end up to decrement d->valid_evtchns. >>> >>> Given that evtchn_status() can work on the non-current domain, it would >>> be possible to run it concurrently with evtchn_destroy(). As a >>> consequence, port_is_valid() will be unstable as a valid event channel >>> may turn invalid. >>> >>> AFAICT, we are getting away so far, as the memory is not freed until the >>> domain is fully destroyed. However, we re-introduced XSA-338 in a >>> different way. >>> >>> To be clear this is not the fault of this patch. But I don't think this >>> is sane to re-introduce a behavior that lead us to an XSA. >> >> I'm getting confused, I'm afraid, from the varying statements above: >> Are you suggesting this patch does re-introduce bad behavior or not? > > No. I am pointing out that this is widening the bad behavior (again). Since I'd really like to get in some more of this series before the full freeze, and hence I want (need) to re-post, I thought I'd reply here despite (or in light of) your request for input from others not having been met. I don't view this as "bad" behaviour, btw. The situation is quite different to that which had led to the XSA: Here we only deal with the "illusion" of a port having become invalid. IOW yes, ... >> Yes, the decrementing of ->valid_evtchns has a similar effect, but >> I'm not convinced it gets us into XSA territory again. The problem >> wasn't the reducing of ->max_evtchns as such, but the derived >> assumptions elsewhere in the code. If there were any such again, I >> suppose we'd have reason to issue another XSA. > > I don't think it get us to the XSA territory yet. However, the > locking/interaction in the event channel code is quite complex. > > To give a concrete example, below the current implementation of > free_xen_event_channel(): > > if ( !port_is_valid(d, port) ) > { > /* > * Make sure ->is_dying is read /after/ ->valid_evtchns, pairing > * with the spin_barrier() and BUG_ON() in evtchn_destroy(). > */ > smp_rmb(); > BUG_ON(!d->is_dying); > return; > } > > evtchn_close(d, port, 0); > > It would be fair for a developer to assume that after the check above, > port_is_valid() would return true. However, this is not the case... ... there needs to be awareness that putting e.g. ASSERT(port_is_valid(d, port)); anywhere past the if() cannot be done without considering domain cleanup logic. > I am not aware of any issue so far... But I am not ready to be this is > not going to be missed out. How about you? There is a risk of this being overlooked, yes. But I'm unconvinced this absolutely requires measures to be taken beyond, maybe, the addition of a comment somewhere. I do, in particular, not think this should stand in the way of the locking relaxation done by this patch, even more so that (just to repeat) it merely introduces more instances of a pattern found elsewhere already. Jan