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=-8.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 1E006C4363A for ; Tue, 20 Oct 2020 14:13: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 9F9DF2098B for ; Tue, 20 Oct 2020 14:13:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="p4jvDGv3" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F9DF2098B 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.9675.25441 (Exim 4.92) (envelope-from ) id 1kUsOW-0002Ok-H3; Tue, 20 Oct 2020 14:13:44 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 9675.25441; Tue, 20 Oct 2020 14:13:44 +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 1kUsOW-0002Od-DK; Tue, 20 Oct 2020 14:13:44 +0000 Received: by outflank-mailman (input) for mailman id 9675; Tue, 20 Oct 2020 14:13:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kUsOU-0002OV-Vx for xen-devel@lists.xenproject.org; Tue, 20 Oct 2020 14:13:43 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f6f4aeb2-f601-4a71-b4be-12c05831e4f9; Tue, 20 Oct 2020 14:13:42 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7BE94AF72; Tue, 20 Oct 2020 14:13:41 +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 1kUsOU-0002OV-Vx for xen-devel@lists.xenproject.org; Tue, 20 Oct 2020 14:13:43 +0000 X-Inumbo-ID: f6f4aeb2-f601-4a71-b4be-12c05831e4f9 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id f6f4aeb2-f601-4a71-b4be-12c05831e4f9; Tue, 20 Oct 2020 14:13:42 +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=1603203221; 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=Zoh/7Mty3v+n/dVbOdwhyCYcVSC+WmCqXrglut1Q6/8=; b=p4jvDGv3U00P7Soo1kqzkIqdMYRpUWl8spkt+u1lNH5V7V7JIhsCJ3/TZttd8JzUChuUao x8ZUDHGoKSl705K4LE9nPyTZvPL1wKeffrIMt+nsc38VoGb0NKkQCVZ1ug101RpGndhTIC KHfE4gE92/RlzDdq7+3O4mif5goXtlA= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7BE94AF72; Tue, 20 Oct 2020 14:13:41 +0000 (UTC) Subject: [PATCH RFC v2 8/8] evtchn: don't call Xen consumer callback with per-channel lock held From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Wei Liu , Stefano Stabellini , Tamas K Lengyel , Alexandru Isaila , Petre Pircalabu References: <19babf20-3649-5c63-44a9-7edfa81835aa@suse.com> Message-ID: <247f0d77-9447-47d0-4fa6-8e17b3e6a6de@suse.com> Date: Tue, 20 Oct 2020 16:13:40 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.1 MIME-Version: 1.0 In-Reply-To: <19babf20-3649-5c63-44a9-7edfa81835aa@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit While there don't look to be any problems with this right now, the lock order implications from holding the lock can be very difficult to follow (and may be easy to violate unknowingly). The present callbacks don't (and no such callback should) have any need for the lock to be held. Signed-off-by: Jan Beulich --- TODO: vm_event_disable() frees the structures used by respective callbacks - need to either use call_rcu() for freeing, or maintain a count of in-progress calls, for evtchn_close() to wait to drop to zero before dropping the lock / returning. --- a/xen/common/event_channel.c +++ b/xen/common/event_channel.c @@ -763,9 +763,18 @@ int evtchn_send(struct domain *ld, unsig rport = lchn->u.interdomain.remote_port; rchn = evtchn_from_port(rd, rport); if ( consumer_is_xen(rchn) ) - xen_notification_fn(rchn)(rd->vcpu[rchn->notify_vcpu_id], rport); - else - evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn); + { + /* Don't keep holding the lock for the call below. */ + xen_event_channel_notification_t fn = xen_notification_fn(rchn); + struct vcpu *rv = rd->vcpu[rchn->notify_vcpu_id]; + + rcu_lock_domain(rd); + spin_unlock_irqrestore(&lchn->lock, flags); + fn(rv, rport); + rcu_unlock_domain(rd); + return 0; + } + evtchn_port_set_pending(rd, rchn->notify_vcpu_id, rchn); break; case ECS_IPI: evtchn_port_set_pending(ld, lchn->notify_vcpu_id, lchn);