From nobody Mon Feb 9 09:28:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=suse.com ARC-Seal: i=1; a=rsa-sha256; t=1604939944; cv=none; d=zohomail.com; s=zohoarc; b=UghNLsCdoG3xMWoYJm4TTGIQYK4EiSLFH4K+lBb7wevKcQ1bdWp946LE+76M0akebjHqECdgbB1v+0YV7uzXWg0EC2RtfLG9V55hTwzb0DaJoWEUjcRAjN9Q1PWuIyCMVsxUX6GHZHCGqkuUCWNmSQU+EW9Ju/EHm4XHzaKHf2o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1604939944; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=DpSBXBI2OHigxodLIbPPZp3jSMwO4fg1IhybSfwcpsI=; b=Ds2Doi2NDZzHZssFdcyTohABUUg6w6RcY7DNhfFKdMWFVEhtUkZdu9SJcmdMB0SSrCTtb8evr0CDZV2YelEPZsvC6A9poYUfn+aOYMImRiMznxRfZLpbhMQLI22tPiXLJdknOqi4L3VTFAQZDR09UAF+pidlW4DiHN5cVpm7+cI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 160493994463541.509613475001174; Mon, 9 Nov 2020 08:39:04 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.22720.49128 (Exim 4.92) (envelope-from ) id 1kcABh-0000yA-4E; Mon, 09 Nov 2020 16:38:37 +0000 Received: by outflank-mailman (output) from mailman id 22720.49128; Mon, 09 Nov 2020 16:38:37 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcABh-0000y2-0z; Mon, 09 Nov 2020 16:38:37 +0000 Received: by outflank-mailman (input) for mailman id 22720; Mon, 09 Nov 2020 16:38:35 +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 1kcABf-0000v8-RJ for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 16:38:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2849798a-e04d-47c6-a55b-07f6f9a5605f; Mon, 09 Nov 2020 16:38:30 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3D9B7AD07; Mon, 9 Nov 2020 16:38:29 +0000 (UTC) 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 1kcABf-0000v8-RJ for xen-devel@lists.xenproject.org; Mon, 09 Nov 2020 16:38:35 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2849798a-e04d-47c6-a55b-07f6f9a5605f; Mon, 09 Nov 2020 16:38:30 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 3D9B7AD07; Mon, 9 Nov 2020 16:38:29 +0000 (UTC) X-Outflank-Mailman: Message body and most headers restored to incoming version 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: 2849798a-e04d-47c6-a55b-07f6f9a5605f 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=1604939909; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=DpSBXBI2OHigxodLIbPPZp3jSMwO4fg1IhybSfwcpsI=; b=mdNDxUawjIsq4LTthLx/DVa/uts2f/PQ0R+BflxXhbQ8CoXQShaIrahQInkijFeozpq6AY vg94KekXePLAYQJSpJQz2fc+O+rLhSWsIS1PvoSzq5xgs7mQkd+JswsKJBZYQr5CuwUlG4 SIMK80I89bVcO8tudmJD3H5tUsik97w= From: Juergen Gross To: xen-devel@lists.xenproject.org Cc: Juergen Gross , Andrew Cooper , George Dunlap , Ian Jackson , Jan Beulich , Julien Grall , Stefano Stabellini , Wei Liu , Julien Grall Subject: [PATCH v6 1/3] xen/events: access last_priority and last_vcpu_id together Date: Mon, 9 Nov 2020 17:38:24 +0100 Message-Id: <20201109163826.13035-2-jgross@suse.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201109163826.13035-1-jgross@suse.com> References: <20201109163826.13035-1-jgross@suse.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @suse.com) Content-Type: text/plain; charset="utf-8" The queue for a fifo event is depending on the vcpu_id and the priority of the event. When sending an event it might happen the event needs to change queues and the old queue needs to be kept for keeping the links between queue elements intact. For this purpose the event channel contains last_priority and last_vcpu_id values elements for being able to identify the old queue. In order to avoid races always access last_priority and last_vcpu_id with a single atomic operation avoiding any inconsistencies. Signed-off-by: Juergen Gross Reviewed-by: Julien Grall --- xen/common/event_fifo.c | 25 +++++++++++++++++++------ xen/include/xen/sched.h | 3 +-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/xen/common/event_fifo.c b/xen/common/event_fifo.c index c6e58d2a1a..79090c04ca 100644 --- a/xen/common/event_fifo.c +++ b/xen/common/event_fifo.c @@ -42,6 +42,14 @@ struct evtchn_fifo_domain { unsigned int num_evtchns; }; =20 +union evtchn_fifo_lastq { + uint32_t raw; + struct { + uint8_t last_priority; + uint16_t last_vcpu_id; + }; +}; + static inline event_word_t *evtchn_fifo_word_from_port(const struct domain= *d, unsigned int port) { @@ -86,16 +94,18 @@ static struct evtchn_fifo_queue *lock_old_queue(const s= truct domain *d, struct vcpu *v; struct evtchn_fifo_queue *q, *old_q; unsigned int try; + union evtchn_fifo_lastq lastq; =20 for ( try =3D 0; try < 3; try++ ) { - v =3D d->vcpu[evtchn->last_vcpu_id]; - old_q =3D &v->evtchn_fifo->queue[evtchn->last_priority]; + lastq.raw =3D read_atomic(&evtchn->fifo_lastq); + v =3D d->vcpu[lastq.last_vcpu_id]; + old_q =3D &v->evtchn_fifo->queue[lastq.last_priority]; =20 spin_lock_irqsave(&old_q->lock, *flags); =20 - v =3D d->vcpu[evtchn->last_vcpu_id]; - q =3D &v->evtchn_fifo->queue[evtchn->last_priority]; + v =3D d->vcpu[lastq.last_vcpu_id]; + q =3D &v->evtchn_fifo->queue[lastq.last_priority]; =20 if ( old_q =3D=3D q ) return old_q; @@ -246,8 +256,11 @@ static void evtchn_fifo_set_pending(struct vcpu *v, st= ruct evtchn *evtchn) /* Moved to a different queue? */ if ( old_q !=3D q ) { - evtchn->last_vcpu_id =3D v->vcpu_id; - evtchn->last_priority =3D q->priority; + union evtchn_fifo_lastq lastq =3D { }; + + lastq.last_vcpu_id =3D v->vcpu_id; + lastq.last_priority =3D q->priority; + write_atomic(&evtchn->fifo_lastq, lastq.raw); =20 spin_unlock_irqrestore(&old_q->lock, flags); spin_lock_irqsave(&q->lock, flags); diff --git a/xen/include/xen/sched.h b/xen/include/xen/sched.h index d8ed83f869..a298ff4df8 100644 --- a/xen/include/xen/sched.h +++ b/xen/include/xen/sched.h @@ -114,8 +114,7 @@ struct evtchn u16 virq; /* state =3D=3D ECS_VIRQ */ } u; u8 priority; - u8 last_priority; - u16 last_vcpu_id; + u32 fifo_lastq; /* Data for fifo events identifying last queue. */ #ifdef CONFIG_XSM union { #ifdef XSM_NEED_GENERIC_EVTCHN_SSID --=20 2.26.2