From patchwork Fri Nov 20 09:48:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11919861 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT 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 4424AC64E69 for ; Fri, 20 Nov 2020 09:49:29 +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 BCD2A204EF for ; Fri, 20 Nov 2020 09:49:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="gnp2dlZA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BCD2A204EF Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=xen.org 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.31838.62614 (Exim 4.92) (envelope-from ) id 1kg32U-0005Ix-SY; Fri, 20 Nov 2020 09:49:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 31838.62614; Fri, 20 Nov 2020 09:49:10 +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 1kg32U-0005In-Ny; Fri, 20 Nov 2020 09:49:10 +0000 Received: by outflank-mailman (input) for mailman id 31838; Fri, 20 Nov 2020 09:49:09 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kg32T-0005Fv-82 for xen-devel@lists.xenproject.org; Fri, 20 Nov 2020 09:49:09 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kg32T-0002b7-1R; Fri, 20 Nov 2020 09:49:09 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kg32S-0003d1-Pk; Fri, 20 Nov 2020 09:49:09 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kg32T-0005Fv-82 for xen-devel@lists.xenproject.org; Fri, 20 Nov 2020 09:49:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=Ie9PO+o0rvIAgtu6WNO10yIOs6iLnaU4in65atV0VQo=; b=gnp2dlZA0e7aR/3BvFD3stzOWH A1BZx8iZK2Y4sf4HB69F3sRKG/RPFfATyGo4WyT/uDS4EznqJNSrgvjAeFem6DKqMrkIaySJmAkxK PoL1J7qBlrXVNZM1HzDbxVv7qFbxvNRjWxgM6/pp+TzKiRH/QvBiMYS9Cv3G+eeZ6zqs=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kg32T-0002b7-1R; Fri, 20 Nov 2020 09:49:09 +0000 Received: from host109-146-187-185.range109-146.btcentralplus.com ([109.146.187.185] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kg32S-0003d1-Pk; Fri, 20 Nov 2020 09:49:09 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Wei Liu , Jan Beulich , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v2 05/12] viridian: use hypercall_vpmask in hvcall_ipi() Date: Fri, 20 Nov 2020 09:48:53 +0000 Message-Id: <20201120094900.1489-6-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201120094900.1489-1-paul@xen.org> References: <20201120094900.1489-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant A subsequent patch will need to IPI a mask of virtual processors potentially wider than 64 bits. A previous patch introduced per-cpu hypercall_vpmask to allow hvcall_flush() to deal with such wide masks. This patch modifies the implementation of hvcall_ipi() to make use of the same mask structures, introducing a for_each_vp() macro to facilitate traversing a mask. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v2: - Drop the 'vp' loop now that vpmask_set() will do it internally --- xen/arch/x86/hvm/viridian/viridian.c | 43 +++++++++++++++++++++------- 1 file changed, 32 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 334d8527ff59..d8d8ecc89c80 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -551,6 +551,25 @@ static bool vpmask_test(const struct hypercall_vpmask *vpmask, return test_bit(vp, vpmask->mask); } +static unsigned int vpmask_first(struct hypercall_vpmask *vpmask) +{ + return find_first_bit(vpmask->mask, HVM_MAX_VCPUS); +} + +static unsigned int vpmask_next(struct hypercall_vpmask *vpmask, unsigned int vp) +{ + /* + * If vp + 1 > HVM_MAX_VCPUS then find_next_bit() will return + * HVM_MAX_VCPUS, ensuring the for_each_vp ( ... ) loop terminates. + */ + return find_next_bit(vpmask->mask, HVM_MAX_VCPUS, vp + 1); +} + +#define for_each_vp(vpmask, vp) \ + for ( (vp) = vpmask_first(vpmask); \ + (vp) < HVM_MAX_VCPUS; \ + (vp) = vpmask_next(vpmask, vp) ) + /* * Windows should not issue the hypercalls requiring this callback in the * case where vcpu_id would exceed the size of the mask. @@ -631,13 +650,21 @@ static int hvcall_flush(union hypercall_input *input, return 0; } +static void send_ipi(struct hypercall_vpmask *vpmask, uint8_t vector) +{ + struct domain *currd = current->domain; + unsigned int vp; + + for_each_vp ( vpmask, vp ) + vlapic_set_irq(vcpu_vlapic(currd->vcpu[vp]), vector, 0); +} + static int hvcall_ipi(union hypercall_input *input, union hypercall_output *output, unsigned long input_params_gpa, unsigned long output_params_gpa) { - struct domain *currd = current->domain; - struct vcpu *v; + struct hypercall_vpmask *vpmask = &this_cpu(hypercall_vpmask); uint32_t vector; uint64_t vcpu_mask; @@ -676,16 +703,10 @@ static int hvcall_ipi(union hypercall_input *input, if ( vector < 0x10 || vector > 0xff ) return -EINVAL; - for_each_vcpu ( currd, v ) - { - if ( v->vcpu_id >= (sizeof(vcpu_mask) * 8) ) - return -EINVAL; + vpmask_empty(vpmask); + vpmask_set(vpmask, 0, vcpu_mask); - if ( !(vcpu_mask & (1ul << v->vcpu_id)) ) - continue; - - vlapic_set_irq(vcpu_vlapic(v), vector, 0); - } + send_ipi(vpmask, vector); return 0; }