From patchwork Mon Sep 28 10:58:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Beulich X-Patchwork-Id: 11803421 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5649D1580 for ; Mon, 28 Sep 2020 10:59:43 +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 251FD2074F for ; Mon, 28 Sep 2020 10:59:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="gfxh9ZIO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 251FD2074F 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 localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kMqrs-0004aq-L6; Mon, 28 Sep 2020 10:58:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kMqrs-0004ak-0L for xen-devel@lists.xenproject.org; Mon, 28 Sep 2020 10:58:52 +0000 X-Inumbo-ID: 97f7edf5-d8a0-4cae-8d7a-53e25c6143e9 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 97f7edf5-d8a0-4cae-8d7a-53e25c6143e9; Mon, 28 Sep 2020 10:58:51 +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=1601290730; 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=fXan/rIQLrp6e3jD5KfkNxF5GmzyEUYe+HppsckrcEs=; b=gfxh9ZIOQVCsGQ8RpS0yY7MifqXvz5qhcRNXcNlqwKTY6iU07pjr2zEGxw39lKgTGh1xDZ bGnina5DUQNwP2+aKjsaRWKyM01UNpVfO7jA6OyAOY0dSHA8Y2BR2h6GzSx7NclhwTbUVz YqY5D98wSVTR+xCbGX7zCnflNBpXFNU= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 666F1AE07; Mon, 28 Sep 2020 10:58:50 +0000 (UTC) Subject: [PATCH 05/12] evtchn/sched: reject poll requests for unusable ports From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , George Dunlap , Ian Jackson , Julien Grall , Wei Liu , Stefano Stabellini , Dario Faggioli References: <0d5ffc89-4b04-3e06-e950-f0cb171c7419@suse.com> Message-ID: <802a0866-6bcf-cb52-1c3f-edb628fbc9c7@suse.com> Date: Mon, 28 Sep 2020 12:58:49 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <0d5ffc89-4b04-3e06-e950-f0cb171c7419@suse.com> Content-Language: en-US X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Before and after XSA-342 there has been an asymmetry in how not really usable ports get treated in do_poll(): Ones beyond a certain boundary (max_evtchns originally, valid_evtchns subsequently) did get refused with -EINVAL, while lower ones were accepted despite there potentially being no way to wake the vCPU again from its polling state. Arrange to also honor evtchn_usable() output in the decision. Requested-by: Andrew Cooper Signed-off-by: Jan Beulich Reviewed-by: Julien Grall Reviewed-by: Dario Faggioli Reviewed-by: Paul Durrant --- a/xen/common/sched/core.c +++ b/xen/common/sched/core.c @@ -1427,13 +1427,13 @@ static long do_poll(struct sched_poll *s if ( __copy_from_guest_offset(&port, sched_poll->ports, i, 1) ) goto out; - rc = -EINVAL; - if ( !port_is_valid(d, port) ) - goto out; - - rc = 0; - if ( evtchn_port_is_pending(d, port) ) + rc = evtchn_port_poll(d, port); + if ( rc ) + { + if ( rc > 0 ) + rc = 0; goto out; + } } if ( sched_poll->nr_ports == 1 ) --- a/xen/include/xen/event.h +++ b/xen/include/xen/event.h @@ -240,19 +240,6 @@ static inline bool evtchn_is_pending(con return evtchn_usable(evtchn) && d->evtchn_port_ops->is_pending(d, evtchn); } -static inline bool evtchn_port_is_pending(struct domain *d, evtchn_port_t port) -{ - struct evtchn *evtchn = evtchn_from_port(d, port); - bool rc; - unsigned long flags; - - spin_lock_irqsave(&evtchn->lock, flags); - rc = evtchn_is_pending(d, evtchn); - spin_unlock_irqrestore(&evtchn->lock, flags); - - return rc; -} - static inline bool evtchn_is_masked(const struct domain *d, const struct evtchn *evtchn) { @@ -279,6 +266,24 @@ static inline bool evtchn_is_busy(const d->evtchn_port_ops->is_busy(d, evtchn); } +static inline int evtchn_port_poll(struct domain *d, evtchn_port_t port) +{ + int rc = -EINVAL; + + if ( port_is_valid(d, port) ) + { + struct evtchn *evtchn = evtchn_from_port(d, port); + unsigned long flags; + + spin_lock_irqsave(&evtchn->lock, flags); + if ( evtchn_usable(evtchn) ) + rc = evtchn_is_pending(d, evtchn); + spin_unlock_irqrestore(&evtchn->lock, flags); + } + + return rc; +} + static inline int evtchn_port_set_priority(struct domain *d, struct evtchn *evtchn, unsigned int priority)