Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3526723pxf; Mon, 15 Mar 2021 11:31:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwt/3EGhmBsxcS//vgnT6IQLqPszemg5s3RgaA1qA/TGqyXMm9yhMKFLTcNw7JjmG9Lu3A+ X-Received: by 2002:a17:906:fcc7:: with SMTP id qx7mr25257601ejb.486.1615833103861; Mon, 15 Mar 2021 11:31:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615833103; cv=none; d=google.com; s=arc-20160816; b=NzgRijzAIf/2gxTdqawdHbDp5GIQjHsAnjKGbhjhWIAl7eRshK2WBzDJYiLU8anJrF x1/SloTlHXGSnNyvr1T+MO/04B9A0HdceiXwHlweo36tCRWuO4cWdKLmHd0Q+Hs4rcnz hB04Vefii1RBG80h1bJ+Oqn08ihSE6xEuhY2sQaKpcTt3P00+M8a184jkhRq28U3FsPB FqfVLmFrz9Wq0rEPlUkWvZv6wRkaiw1MgaR8PoV4dxnP+1csoZVxDuQ6tUKgDsWUTtAt PpEhJmsf6HHmNm8LGgM5OCqhGXowD18hHu/GiaVYaUSkxCcRp9I846Un5KJvmImptViL IbMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=iqdNs7TctNdDs5WGwygL23ckHimWwxZDZe2b6FVYibs=; b=Qrvr03sqylxUrUziwN41tb8P6rvRlAQEckocxEikQNDWtx/f8cykQNmCkaVsayEzCe rNs1gO+TrD+k9iNpL4V8uM9XX6M0tpxmYRdatHpbMiq2NdWovAJybKuANUP30+2T9ecl PIHAzJwoVeBOpV0rGY48AiqS9UjZbsFXFDKsQLPLvHqBQxnT/xsiZeX0//2ELiRZCn3f SSOhqyPo31kTR9uFmctVoRsJ5jynErfdiVv4MlaRwivZY5omZNtkgpsiGuvGpEUBc2zW aUuGwAz5mFuHYgywnNHFP26wdwxYW+ah9HCl9OE1QrqO5XjUIICwJbFnDBi57l28s9Hk bX/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aX1MghLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gx21si11639077ejc.503.2021.03.15.11.31.22; Mon, 15 Mar 2021 11:31:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=aX1MghLv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235967AbhCOOfZ (ORCPT + 99 others); Mon, 15 Mar 2021 10:35:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:37836 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233462AbhCOOBn (ORCPT ); Mon, 15 Mar 2021 10:01:43 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2470164F38; Mon, 15 Mar 2021 14:01:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816896; bh=AxPi8iIYZO4rywVvF38szy8NSw/wfh2e9cH7+M+UJAM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=aX1MghLvO/0wNBeRbnfFakf5aDYq5eBOoz/rooeeun4jPjUoG5722fU48TgT2MwJy YrbwYvJLr0Wz6FnLV+C5W4qBJPcLBr993o4PZ4aXEBp5JwguntYdMMSjIoNjVU/dHP ZBqJkZkcVfIZlqkjLEXXDgS2n3KXNv8kCtSu7MJA= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Julien Grall , Juergen Gross , Julien Grall , Boris Ostrovsky Subject: [PATCH 5.11 188/306] xen/events: avoid handling the same event on two cpus at the same time Date: Mon, 15 Mar 2021 14:54:11 +0100 Message-Id: <20210315135513.969938977@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135507.611436477@linuxfoundation.org> References: <20210315135507.611436477@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Juergen Gross commit b6622798bc50b625a1e62f82c7190df40c1f5b21 upstream. When changing the cpu affinity of an event it can happen today that (with some unlucky timing) the same event will be handled on the old and the new cpu at the same time. Avoid that by adding an "event active" flag to the per-event data and call the handler only if this flag isn't set. Cc: stable@vger.kernel.org Reported-by: Julien Grall Signed-off-by: Juergen Gross Reviewed-by: Julien Grall Link: https://lore.kernel.org/r/20210306161833.4552-4-jgross@suse.com Signed-off-by: Boris Ostrovsky Signed-off-by: Greg Kroah-Hartman --- drivers/xen/events/events_base.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -102,6 +102,7 @@ struct irq_info { #define EVT_MASK_REASON_EXPLICIT 0x01 #define EVT_MASK_REASON_TEMPORARY 0x02 #define EVT_MASK_REASON_EOI_PENDING 0x04 + u8 is_active; /* Is event just being handled? */ unsigned irq; evtchn_port_t evtchn; /* event channel */ unsigned short cpu; /* cpu bound */ @@ -791,6 +792,12 @@ static void xen_evtchn_close(evtchn_port BUG(); } +static void event_handler_exit(struct irq_info *info) +{ + smp_store_release(&info->is_active, 0); + clear_evtchn(info->evtchn); +} + static void pirq_query_unmask(int irq) { struct physdev_irq_status_query irq_status; @@ -809,14 +816,15 @@ static void pirq_query_unmask(int irq) static void eoi_pirq(struct irq_data *data) { - evtchn_port_t evtchn = evtchn_from_irq(data->irq); + struct irq_info *info = info_for_irq(data->irq); + evtchn_port_t evtchn = info ? info->evtchn : 0; struct physdev_eoi eoi = { .irq = pirq_from_irq(data->irq) }; int rc = 0; if (!VALID_EVTCHN(evtchn)) return; - clear_evtchn(evtchn); + event_handler_exit(info); if (pirq_needs_eoi(data->irq)) { rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); @@ -1640,6 +1648,8 @@ void handle_irq_for_port(evtchn_port_t p } info = info_for_irq(irq); + if (xchg_acquire(&info->is_active, 1)) + return; if (ctrl->defer_eoi) { info->eoi_cpu = smp_processor_id(); @@ -1823,12 +1833,11 @@ static void disable_dynirq(struct irq_da static void ack_dynirq(struct irq_data *data) { - evtchn_port_t evtchn = evtchn_from_irq(data->irq); - - if (!VALID_EVTCHN(evtchn)) - return; + struct irq_info *info = info_for_irq(data->irq); + evtchn_port_t evtchn = info ? info->evtchn : 0; - clear_evtchn(evtchn); + if (VALID_EVTCHN(evtchn)) + event_handler_exit(info); } static void mask_ack_dynirq(struct irq_data *data) @@ -1844,7 +1853,7 @@ static void lateeoi_ack_dynirq(struct ir if (VALID_EVTCHN(evtchn)) { do_mask(info, EVT_MASK_REASON_EOI_PENDING); - clear_evtchn(evtchn); + event_handler_exit(info); } } @@ -1855,7 +1864,7 @@ static void lateeoi_mask_ack_dynirq(stru if (VALID_EVTCHN(evtchn)) { do_mask(info, EVT_MASK_REASON_EXPLICIT); - clear_evtchn(evtchn); + event_handler_exit(info); } } @@ -1968,10 +1977,11 @@ static void restore_cpu_ipis(unsigned in /* Clear an irq's pending state, in preparation for polling on it */ void xen_clear_irq_pending(int irq) { - evtchn_port_t evtchn = evtchn_from_irq(irq); + struct irq_info *info = info_for_irq(irq); + evtchn_port_t evtchn = info ? info->evtchn : 0; if (VALID_EVTCHN(evtchn)) - clear_evtchn(evtchn); + event_handler_exit(info); } EXPORT_SYMBOL(xen_clear_irq_pending); void xen_set_irq_pending(int irq)