From mboxrd@z Thu Jan 1 00:00:00 1970 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 5AA64C64E7B for ; Tue, 24 Nov 2020 19:08:11 +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 D8452208DB for ; Tue, 24 Nov 2020 19:08:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=xen.org header.i=@xen.org header.b="5RIRBHRq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D8452208DB 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.36807.68871 (Exim 4.92) (envelope-from ) id 1khdfL-0001N9-Ta; Tue, 24 Nov 2020 19:07:51 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 36807.68871; Tue, 24 Nov 2020 19:07:51 +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 1khdfL-0001N1-Ox; Tue, 24 Nov 2020 19:07:51 +0000 Received: by outflank-mailman (input) for mailman id 36807; Tue, 24 Nov 2020 19:07:50 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfK-0001Kt-ME for xen-devel@lists.xenproject.org; Tue, 24 Nov 2020 19:07:50 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfK-0003sw-Ek; Tue, 24 Nov 2020 19:07:50 +0000 Received: from host86-183-162-145.range86-183.btcentralplus.com ([86.183.162.145] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khdfK-0000r4-5c; Tue, 24 Nov 2020 19:07:50 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfK-0001Kt-ME for xen-devel@lists.xenproject.org; Tue, 24 Nov 2020 19:07:50 +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=P1UWM8Y+y7SpMZ1c9aQQbLpHv68ZojqNnpvFbtmz8y4=; b=5RIRBHRqUGGDoqY2zzRhwo8mf7 K8YpAjt0IwkIocNWyMN1VfeNOn1Gz9Yt5nJpw5t/onHrRMvLYojhRdPDer4D27L9ifP227RwVDwOk 91VB2zi8TaOinO/UKvJkGYbLT73JW1KDl4UwNOWJM1VJf8lByjTOz/YqdP4nuXA7HLWQ=; Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1khdfK-0003sw-Ek; Tue, 24 Nov 2020 19:07:50 +0000 Received: from host86-183-162-145.range86-183.btcentralplus.com ([86.183.162.145] helo=u2f063a87eabd5f.home) by xenbits.xenproject.org with esmtpsa (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1khdfK-0000r4-5c; Tue, 24 Nov 2020 19:07:50 +0000 From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Wei Liu , Jan Beulich , Andrew Cooper , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Subject: [PATCH v3 04/13] viridian: introduce a per-cpu hypercall_vpmask and accessor functions... Date: Tue, 24 Nov 2020 19:07:35 +0000 Message-Id: <20201124190744.11343-5-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201124190744.11343-1-paul@xen.org> References: <20201124190744.11343-1-paul@xen.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Paul Durrant ... and make use of them in hvcall_flush()/need_flush(). Subsequent patches will need to deal with virtual processor masks potentially wider than 64 bits. Thus, to avoid using too much stack, this patch introduces global per-cpu virtual processor masks and converts the implementation of hvcall_flush() to use them. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v2: - Modified vpmask_set() to take a base 'vp' and a 64-bit 'mask', still looping over the mask as bitmap.h does not provide a primitive for copying one mask into another at an offset - Added ASSERTions to verify that we don't attempt to set or test bits beyond the limit of the map --- xen/arch/x86/hvm/viridian/viridian.c | 58 ++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 4 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 8ac1b32565a8..d8f47b8528a2 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -507,15 +507,59 @@ void viridian_domain_deinit(struct domain *d) XFREE(d->arch.hvm.viridian); } +struct hypercall_vpmask { + DECLARE_BITMAP(mask, HVM_MAX_VCPUS); +}; + +static DEFINE_PER_CPU(struct hypercall_vpmask, hypercall_vpmask); + +static void vpmask_empty(struct hypercall_vpmask *vpmask) +{ + bitmap_zero(vpmask->mask, HVM_MAX_VCPUS); +} + +static void vpmask_set(struct hypercall_vpmask *vpmask, unsigned int vp, + uint64_t mask) +{ + unsigned int count = sizeof(mask) * 8; + + while ( count-- ) + { + if ( !mask ) + break; + + if ( mask & 1 ) + { + ASSERT(vp < HVM_MAX_VCPUS); + __set_bit(vp, vpmask->mask); + } + + mask >>= 1; + vp++; + } +} + +static void vpmask_fill(struct hypercall_vpmask *vpmask) +{ + bitmap_fill(vpmask->mask, HVM_MAX_VCPUS); +} + +static bool vpmask_test(const struct hypercall_vpmask *vpmask, + unsigned int vp) +{ + ASSERT(vp < HVM_MAX_VCPUS); + return test_bit(vp, vpmask->mask); +} + /* * Windows should not issue the hypercalls requiring this callback in the * case where vcpu_id would exceed the size of the mask. */ static bool need_flush(void *ctxt, struct vcpu *v) { - uint64_t vcpu_mask = *(uint64_t *)ctxt; + struct hypercall_vpmask *vpmask = ctxt; - return vcpu_mask & (1ul << v->vcpu_id); + return vpmask_test(vpmask, v->vcpu_id); } union hypercall_input { @@ -546,6 +590,7 @@ static int hvcall_flush(const union hypercall_input *input, paddr_t input_params_gpa, paddr_t output_params_gpa) { + struct hypercall_vpmask *vpmask = &this_cpu(hypercall_vpmask); struct { uint64_t address_space; uint64_t flags; @@ -567,13 +612,18 @@ static int hvcall_flush(const union hypercall_input *input, * so err on the safe side. */ if ( input_params.flags & HV_FLUSH_ALL_PROCESSORS ) - input_params.vcpu_mask = ~0ul; + vpmask_fill(vpmask); + else + { + vpmask_empty(vpmask); + vpmask_set(vpmask, 0, input_params.vcpu_mask); + } /* * A false return means that another vcpu is currently trying * a similar operation, so back off. */ - if ( !paging_flush_tlb(need_flush, &input_params.vcpu_mask) ) + if ( !paging_flush_tlb(need_flush, vpmask) ) return -ERESTART; output->rep_complete = input->rep_count; -- 2.20.1