Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3316276pxf; Mon, 15 Mar 2021 07:01:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqp0a8NElI+hPzR1bVhWquS8WvIlppU3faylhqRqbxf2Y/ZDQbrNd36RtaXJnlGn5m1OZ2 X-Received: by 2002:a17:906:3388:: with SMTP id v8mr24076825eja.278.1615816913706; Mon, 15 Mar 2021 07:01:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615816913; cv=none; d=google.com; s=arc-20160816; b=RBN21V4X8uIIdwKBdTqZNaPkDjp5mT7HYdPHI9IucR71iVMa2OMB+AHcNP4TWZoA/F 0evL5uxMW6ZwY6grPEuPey49ljAtFfOnoCMhPmGklcPfMFSTH6gcgQ4cYEIoj37k0fo6 dPbOp8Sq2YuJ2MEXqrXw8skW1h88ze1eknpdQG4oGgWgv9cQ2LBUJQVzwErNMz0q+epG wnHt+pitAjCe29yymXWd0lNtJnJF4PkqTsBbNpdFT4LzUIZF1Cx79fSiYn1TMhFhEK2C dlxDOi0S9l3/Rf+dwKhlfLRRp/j+0v56HwKVWWMz8S/yBkImGONTj4Wjfy6STShIm1n9 PyMw== 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=uDY5fqj79MzL7ehaaDicifB9rDZfdEIB7fGKN9gVKE0=; b=jL3XYv01G5DoWhCiGoVefj9lLAoHuPUTg868TzFwfnSCm90N51f+Fc04Kbp5gNKfmh gDybnhAxdhRV9bxgytNWRJrILDQOiYNa8WJzTodsdYzDI0JjUoYRSf2FRxDYJhI01YAP S+MZVlKu+YeiO/c4btAjOiNDj4DySUjK0aH1wFmLkWWjlGRklOozgoREMULjmFFtYw77 APmwUWYUido6Z2eqcOCM+qAxBumm5ZvE6FU873NLI6ByD3uEtUPUpZ2jMgVtdbk1C8yu Clfl3Ho6Z6/6YY2P025AQ2O4mSC5MRcCus/Y40JYaE5v2OeimVVv6gE9zPhrtymDmXIH BUQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=kBIQ5BZC; 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 g14si11081795edr.362.2021.03.15.07.01.29; Mon, 15 Mar 2021 07:01:53 -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=kBIQ5BZC; 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 S232904AbhCOOAG (ORCPT + 99 others); Mon, 15 Mar 2021 10:00:06 -0400 Received: from mail.kernel.org ([198.145.29.99]:59402 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231713AbhCONzK (ORCPT ); Mon, 15 Mar 2021 09:55:10 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5332A64EB6; Mon, 15 Mar 2021 13:55:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816510; bh=+a99zkgVXIsOsSy2xm8mD7Pb7cBSn8jGKLpGXBnAiAU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kBIQ5BZCpB59dKApEUE93VhKdyO+k1elZAWo/Vta6+aaj4VCFXiS5QSO9wOz434Kq Kj++3eSIIxJwdVSYjHzOaLEu58Ll+4M+u44TYV9G6LAh3eBRWxP97sOOkKR8HS+HHN nH8Ock8Bmta2ylJCUxIO7o9OLi1oZ5sBHYJG1+xc= 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 4.9 78/78] xen/events: avoid handling the same event on two cpus at the same time Date: Mon, 15 Mar 2021 14:52:41 +0100 Message-Id: <20210315135214.612976968@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135212.060847074@linuxfoundation.org> References: <20210315135212.060847074@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 | 25 +++++++++++++++++-------- drivers/xen/events/events_internal.h | 1 + 2 files changed, 18 insertions(+), 8 deletions(-) --- a/drivers/xen/events/events_base.c +++ b/drivers/xen/events/events_base.c @@ -702,6 +702,12 @@ static void xen_evtchn_close(unsigned in 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; @@ -732,13 +738,13 @@ static void eoi_pirq(struct irq_data *da likely(!irqd_irq_disabled(data))) { do_mask(info, EVT_MASK_REASON_TEMPORARY); - clear_evtchn(evtchn); + event_handler_exit(info); irq_move_masked_irq(data); do_unmask(info, EVT_MASK_REASON_TEMPORARY); } else - clear_evtchn(evtchn); + event_handler_exit(info); if (pirq_needs_eoi(data->irq)) { rc = HYPERVISOR_physdev_op(PHYSDEVOP_eoi, &eoi); @@ -1574,6 +1580,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(); @@ -1750,13 +1758,13 @@ static void ack_dynirq(struct irq_data * likely(!irqd_irq_disabled(data))) { do_mask(info, EVT_MASK_REASON_TEMPORARY); - clear_evtchn(evtchn); + event_handler_exit(info); irq_move_masked_irq(data); do_unmask(info, EVT_MASK_REASON_TEMPORARY); } else - clear_evtchn(evtchn); + event_handler_exit(info); } static void mask_ack_dynirq(struct irq_data *data) @@ -1772,7 +1780,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); } } @@ -1783,7 +1791,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); } } @@ -1892,10 +1900,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) { - int 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) --- a/drivers/xen/events/events_internal.h +++ b/drivers/xen/events/events_internal.h @@ -40,6 +40,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; unsigned int evtchn; /* event channel */ unsigned short cpu; /* cpu bound */