From patchwork Wed Dec 2 09:21:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945363 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.7 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 943AFC71155 for ; Wed, 2 Dec 2020 09:22:24 +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 0E1D622203 for ; Wed, 2 Dec 2020 09:22:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E1D622203 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.42503.76449 (Exim 4.92) (envelope-from ) id 1kkOKw-0002wz-8D; Wed, 02 Dec 2020 09:22:10 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42503.76449; Wed, 02 Dec 2020 09:22:10 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKw-0002ws-3s; Wed, 02 Dec 2020 09:22:10 +0000 Received: by outflank-mailman (input) for mailman id 42503; Wed, 02 Dec 2020 09:22:08 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKu-0002vC-N5 for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:08 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKu-0004q2-Br; Wed, 02 Dec 2020 09:22:08 +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 1kkOKu-0006CD-31; Wed, 02 Dec 2020 09:22:08 +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" 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=wsUSjMIuCJSFEzqOPxy9cU/RRj5MGvZk3yge+ryDxEU=; b=6cgIRj9yLenRSlm1Lk0kmN45G8 YduZiUpQZwQ0rsalsdiyU42/NGcjtjwRdiSDlegGMocN5ImisRx6T6vjwAwUhNyoHP8sfQkooaLBX HSLiX7HdBZcenn+KEyIVEILfDpM7aOHbneE2pnc64jNSlrzmMbg/cnzvYgkcbZDel1lU=; 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 v4 01/11] viridian: don't blindly write to 32-bit registers is 'mode' is invalid Date: Wed, 2 Dec 2020 09:21:57 +0000 Message-Id: <20201202092205.906-2-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant If hvm_guest_x86_mode() returns something other than 8 or 4 then viridian_hypercall() will return immediately but, on the way out, will write back status as if 'mode' was 4. This patch simply makes it leave the registers alone. NOTE: The formatting of the 'out' label and the switch statement are also adjusted as per CODING_STYLE. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v4: - Fixed another CODING_STYLE violation. v2: - New in v2 --- xen/arch/x86/hvm/viridian/viridian.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index dc7183a54627..338e705bd29c 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -692,13 +692,15 @@ int viridian_hypercall(struct cpu_user_regs *regs) break; } -out: + out: output.result = status; - switch (mode) { + switch (mode) + { case 8: regs->rax = output.raw; break; - default: + + case 4: regs->rdx = output.raw >> 32; regs->rax = (uint32_t)output.raw; break; From patchwork Wed Dec 2 09:21:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945367 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.7 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 BA34EC83013 for ; Wed, 2 Dec 2020 09:22:25 +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 4EEF920C56 for ; Wed, 2 Dec 2020 09:22:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4EEF920C56 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.42504.76460 (Exim 4.92) (envelope-from ) id 1kkOKx-0002yA-FB; Wed, 02 Dec 2020 09:22:11 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42504.76460; Wed, 02 Dec 2020 09:22:11 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKx-0002y3-C8; Wed, 02 Dec 2020 09:22:11 +0000 Received: by outflank-mailman (input) for mailman id 42504; Wed, 02 Dec 2020 09:22:10 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKv-0002wn-Vj for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:09 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKv-0004q8-Hv; Wed, 02 Dec 2020 09:22:09 +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 1kkOKv-0006CD-7v; Wed, 02 Dec 2020 09:22:09 +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" 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=m2JUzU4YdPfLMUj4CZFPdzmClYqKNkNVCg9Y25SzLOg=; b=p8nVOjA7bj85qCOY/txbqL8F2F bu+tkG9FMj/p+GQeXRJ7wVKN3uLSh/TilbpEjZzCJEWXOdbQPlwz1LPVeeIP4MCn4S1amio/9+T+F l0Okjhe6qoOKtkE6xbnq0l1IH1bBW8ujFqdiWYsE+HpjA3wtJ9PuagcvYFivdeRYeflQ=; 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 v4 02/11] viridian: move flush hypercall implementation into separate function Date: Wed, 2 Dec 2020 09:21:58 +0000 Message-Id: <20201202092205.906-3-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant This patch moves the implementation of HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE/LIST that is currently inline in viridian_hypercall() into a new hvcall_flush() function. The new function returns Xen erro values which are then dealt with appropriately. A return value of -ERESTART translates to viridian_hypercall() returning HVM_HCALL_preempted. Other return values translate to status codes and viridian_hypercall() returning HVM_HCALL_completed. Currently the only values, other than -ERESTART, returned by hvcall_flush() are 0 (indicating success) or -EINVAL. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v3: - Adjust prototype of new function --- xen/arch/x86/hvm/viridian/viridian.c | 130 ++++++++++++++++----------- 1 file changed, 78 insertions(+), 52 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 338e705bd29c..69b6f285e8aa 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -518,6 +518,69 @@ static bool need_flush(void *ctxt, struct vcpu *v) return vcpu_mask & (1ul << v->vcpu_id); } +union hypercall_input { + uint64_t raw; + struct { + uint16_t call_code; + uint16_t fast:1; + uint16_t rsvd1:15; + uint16_t rep_count:12; + uint16_t rsvd2:4; + uint16_t rep_start:12; + uint16_t rsvd3:4; + }; +}; + +union hypercall_output { + uint64_t raw; + struct { + uint16_t result; + uint16_t rsvd1; + uint32_t rep_complete:12; + uint32_t rsvd2:20; + }; +}; + +static int hvcall_flush(const union hypercall_input *input, + union hypercall_output *output, + paddr_t input_params_gpa, + paddr_t output_params_gpa) +{ + struct { + uint64_t address_space; + uint64_t flags; + uint64_t vcpu_mask; + } input_params; + + /* These hypercalls should never use the fast-call convention. */ + if ( input->fast ) + return -EINVAL; + + /* Get input parameters. */ + if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, + sizeof(input_params)) != HVMTRANS_okay ) + return -EINVAL; + + /* + * It is not clear from the spec. if we are supposed to + * include current virtual CPU in the set or not in this case, + * so err on the safe side. + */ + if ( input_params.flags & HV_FLUSH_ALL_PROCESSORS ) + input_params.vcpu_mask = ~0ul; + + /* + * 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) ) + return -ERESTART; + + output->rep_complete = input->rep_count; + + return 0; +} + int viridian_hypercall(struct cpu_user_regs *regs) { struct vcpu *curr = current; @@ -525,29 +588,8 @@ int viridian_hypercall(struct cpu_user_regs *regs) int mode = hvm_guest_x86_mode(curr); unsigned long input_params_gpa, output_params_gpa; uint16_t status = HV_STATUS_SUCCESS; - - union hypercall_input { - uint64_t raw; - struct { - uint16_t call_code; - uint16_t fast:1; - uint16_t rsvd1:15; - uint16_t rep_count:12; - uint16_t rsvd2:4; - uint16_t rep_start:12; - uint16_t rsvd3:4; - }; - } input; - - union hypercall_output { - uint64_t raw; - struct { - uint16_t result; - uint16_t rsvd1; - uint32_t rep_complete:12; - uint32_t rsvd2:20; - }; - } output = { 0 }; + union hypercall_input input; + union hypercall_output output = {}; ASSERT(is_viridian_domain(currd)); @@ -580,41 +622,25 @@ int viridian_hypercall(struct cpu_user_regs *regs) case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: { - struct { - uint64_t address_space; - uint64_t flags; - uint64_t vcpu_mask; - } input_params; + int rc = hvcall_flush(&input, &output, input_params_gpa, + output_params_gpa); - /* These hypercalls should never use the fast-call convention. */ - status = HV_STATUS_INVALID_PARAMETER; - if ( input.fast ) + switch ( rc ) + { + case 0: break; - /* Get input parameters. */ - if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, - sizeof(input_params)) != - HVMTRANS_okay ) - break; - - /* - * It is not clear from the spec. if we are supposed to - * include current virtual CPU in the set or not in this case, - * so err on the safe side. - */ - if ( input_params.flags & HV_FLUSH_ALL_PROCESSORS ) - input_params.vcpu_mask = ~0ul; - - /* - * 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) ) + case -ERESTART: return HVM_HCALL_preempted; - output.rep_complete = input.rep_count; + default: + ASSERT_UNREACHABLE(); + /* Fallthrough */ + case -EINVAL: + status = HV_STATUS_INVALID_PARAMETER; + break; + } - status = HV_STATUS_SUCCESS; break; } From patchwork Wed Dec 2 09:21:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945361 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.7 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 80342C64E7C for ; Wed, 2 Dec 2020 09:22:23 +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 07C8D20C56 for ; Wed, 2 Dec 2020 09:22:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 07C8D20C56 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.42505.76473 (Exim 4.92) (envelope-from ) id 1kkOKy-00030H-Pd; Wed, 02 Dec 2020 09:22:12 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42505.76473; Wed, 02 Dec 2020 09:22:12 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKy-000308-La; Wed, 02 Dec 2020 09:22:12 +0000 Received: by outflank-mailman (input) for mailman id 42505; Wed, 02 Dec 2020 09:22:11 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKw-0002xr-WC for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:11 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKw-0004qF-Ki; Wed, 02 Dec 2020 09:22:10 +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 1kkOKw-0006CD-Cd; Wed, 02 Dec 2020 09:22: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" 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=X3Jg3m4I7HeCYZvOk4GKjZUPANy4lRyYlPfxlQJ1voE=; b=kAA2MBMBgCy7Ave8W2H3ITyF1B /f1++/OK4feg7B8chJOIPCYnyXV+OtTz3UDgiMiyCzgiENFYsDk5YGkaeDLQeLCE/rgXp1RXBdrEb kFoQrVex4IEtX5wJiYtIMXEG7Fp7ytVw/bhsj2hWAeHYgeprtzJZ4WNBORvAYiJPUDnI=; 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 v4 03/11] viridian: move IPI hypercall implementation into separate function Date: Wed, 2 Dec 2020 09:21:59 +0000 Message-Id: <20201202092205.906-4-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant This patch moves the implementation of HVCALL_SEND_IPI that is currently inline in viridian_hypercall() into a new hvcall_ipi() function. The new function returns Xen errno values similarly to hvcall_flush(). Hence the errno translation code in viridial_hypercall() is generalized, removing the need for the local 'status' variable. NOTE: The formatting of the switch statement at the top of viridial_hypercall() is also adjusted as per CODING_STYLE. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v3: - Adjust prototype of new function v2: - Different formatting adjustment --- xen/arch/x86/hvm/viridian/viridian.c | 168 ++++++++++++++------------- 1 file changed, 87 insertions(+), 81 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 69b6f285e8aa..9844bb57872a 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -581,13 +581,72 @@ static int hvcall_flush(const union hypercall_input *input, return 0; } +static int hvcall_ipi(const union hypercall_input *input, + union hypercall_output *output, + paddr_t input_params_gpa, + paddr_t output_params_gpa) +{ + struct domain *currd = current->domain; + struct vcpu *v; + uint32_t vector; + uint64_t vcpu_mask; + + /* Get input parameters. */ + if ( input->fast ) + { + if ( input_params_gpa >> 32 ) + return -EINVAL; + + vector = input_params_gpa; + vcpu_mask = output_params_gpa; + } + else + { + struct { + uint32_t vector; + uint8_t target_vtl; + uint8_t reserved_zero[3]; + uint64_t vcpu_mask; + } input_params; + + if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, + sizeof(input_params)) != HVMTRANS_okay ) + return -EINVAL; + + if ( input_params.target_vtl || + input_params.reserved_zero[0] || + input_params.reserved_zero[1] || + input_params.reserved_zero[2] ) + return -EINVAL; + + vector = input_params.vector; + vcpu_mask = input_params.vcpu_mask; + } + + if ( vector < 0x10 || vector > 0xff ) + return -EINVAL; + + for_each_vcpu ( currd, v ) + { + if ( v->vcpu_id >= (sizeof(vcpu_mask) * 8) ) + return -EINVAL; + + if ( !(vcpu_mask & (1ul << v->vcpu_id)) ) + continue; + + vlapic_set_irq(vcpu_vlapic(v), vector, 0); + } + + return 0; +} + int viridian_hypercall(struct cpu_user_regs *regs) { struct vcpu *curr = current; struct domain *currd = curr->domain; int mode = hvm_guest_x86_mode(curr); unsigned long input_params_gpa, output_params_gpa; - uint16_t status = HV_STATUS_SUCCESS; + int rc = 0; union hypercall_input input; union hypercall_output output = {}; @@ -600,11 +659,13 @@ int viridian_hypercall(struct cpu_user_regs *regs) input_params_gpa = regs->rdx; output_params_gpa = regs->r8; break; + case 4: input.raw = (regs->rdx << 32) | regs->eax; input_params_gpa = (regs->rbx << 32) | regs->ecx; output_params_gpa = (regs->rdi << 32) | regs->esi; break; + default: goto out; } @@ -616,92 +677,18 @@ int viridian_hypercall(struct cpu_user_regs *regs) * See section 14.5.1 of the specification. */ do_sched_op(SCHEDOP_yield, guest_handle_from_ptr(NULL, void)); - status = HV_STATUS_SUCCESS; break; case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: - { - int rc = hvcall_flush(&input, &output, input_params_gpa, - output_params_gpa); - - switch ( rc ) - { - case 0: - break; - - case -ERESTART: - return HVM_HCALL_preempted; - - default: - ASSERT_UNREACHABLE(); - /* Fallthrough */ - case -EINVAL: - status = HV_STATUS_INVALID_PARAMETER; - break; - } - + rc = hvcall_flush(&input, &output, input_params_gpa, + output_params_gpa); break; - } case HVCALL_SEND_IPI: - { - struct vcpu *v; - uint32_t vector; - uint64_t vcpu_mask; - - status = HV_STATUS_INVALID_PARAMETER; - - /* Get input parameters. */ - if ( input.fast ) - { - if ( input_params_gpa >> 32 ) - break; - - vector = input_params_gpa; - vcpu_mask = output_params_gpa; - } - else - { - struct { - uint32_t vector; - uint8_t target_vtl; - uint8_t reserved_zero[3]; - uint64_t vcpu_mask; - } input_params; - - if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, - sizeof(input_params)) != - HVMTRANS_okay ) - break; - - if ( input_params.target_vtl || - input_params.reserved_zero[0] || - input_params.reserved_zero[1] || - input_params.reserved_zero[2] ) - break; - - vector = input_params.vector; - vcpu_mask = input_params.vcpu_mask; - } - - if ( vector < 0x10 || vector > 0xff ) - break; - - for_each_vcpu ( currd, v ) - { - if ( v->vcpu_id >= (sizeof(vcpu_mask) * 8) ) - break; - - if ( !(vcpu_mask & (1ul << v->vcpu_id)) ) - continue; - - vlapic_set_irq(vcpu_vlapic(v), vector, 0); - } - - status = HV_STATUS_SUCCESS; + rc = hvcall_ipi(&input, &output, input_params_gpa, + output_params_gpa); break; - } default: gprintk(XENLOG_WARNING, "unimplemented hypercall %04x\n", @@ -714,12 +701,31 @@ int viridian_hypercall(struct cpu_user_regs *regs) * Given that return a status of 'invalid code' has not so far * caused any problems it's not worth logging. */ - status = HV_STATUS_INVALID_HYPERCALL_CODE; + rc = -EOPNOTSUPP; break; } out: - output.result = status; + switch ( rc ) + { + case 0: + break; + + case -ERESTART: + return HVM_HCALL_preempted; + + case -EOPNOTSUPP: + output.result = HV_STATUS_INVALID_HYPERCALL_CODE; + break; + + default: + ASSERT_UNREACHABLE(); + /* Fallthrough */ + case -EINVAL: + output.result = HV_STATUS_INVALID_PARAMETER; + break; + } + switch (mode) { case 8: From patchwork Wed Dec 2 09:22:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945369 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.7 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 90657C83014 for ; Wed, 2 Dec 2020 09:22:26 +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 1EFBB20872 for ; Wed, 2 Dec 2020 09:22:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1EFBB20872 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.42506.76482 (Exim 4.92) (envelope-from ) id 1kkOKz-00031g-DG; Wed, 02 Dec 2020 09:22:13 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42506.76482; Wed, 02 Dec 2020 09:22:13 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKz-00031M-6t; Wed, 02 Dec 2020 09:22:13 +0000 Received: by outflank-mailman (input) for mailman id 42506; Wed, 02 Dec 2020 09:22:12 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKy-0002zc-2x for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:12 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKx-0004qN-PV; Wed, 02 Dec 2020 09:22:11 +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 1kkOKx-0006CD-HW; Wed, 02 Dec 2020 09:22:11 +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" 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=UQPEbNdpYJUM2Gx6R85h5d+pKLFn2/d5C4V2C8DT2GY=; b=RyAPoQvFW1GcXRJ17jZMSw8iY4 3mhHWJlneSxUBy0AUP+GKcb9LfZS/kT4YjdfkkYaionNTVV16lvmPP7mgORouGQwOD0Zoq9iLthqJ n8TxqxaWPQYUx1ZF/vcicFzJ0nn9PqwdTAUinneX3x2X/k3Sc0lCUfNThwgBl7ecXQyY=; 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 v4 04/11] viridian: introduce a per-cpu hypercall_vpmask and accessor functions... Date: Wed, 2 Dec 2020 09:22:00 +0000 Message-Id: <20201202092205.906-5-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 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 9844bb57872a..cfd87504052f 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; From patchwork Wed Dec 2 09:22:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945377 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.7 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 8C894C83016 for ; Wed, 2 Dec 2020 09:22:27 +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 242A122203 for ; Wed, 2 Dec 2020 09:22:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 242A122203 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.42507.76497 (Exim 4.92) (envelope-from ) id 1kkOL0-00035T-Q0; Wed, 02 Dec 2020 09:22:14 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42507.76497; Wed, 02 Dec 2020 09:22:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL0-00035D-K3; Wed, 02 Dec 2020 09:22:14 +0000 Received: by outflank-mailman (input) for mailman id 42507; Wed, 02 Dec 2020 09:22:13 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKz-00031Q-6e for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:13 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOKy-0004qU-UQ; Wed, 02 Dec 2020 09:22:12 +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 1kkOKy-0006CD-MN; Wed, 02 Dec 2020 09:22:12 +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" 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=K8HbJNFS+eSvzpIgXAlXNXAsJGy5ROLLCyua8HaV7xs=; b=gIzu0rZ6dBx0WfduEYPTaQDnYh 4RFD4aUDl85sqBIqAWo1Utz1Hdon6kXGCjt1TPb7cLqF7XGleXUMtykYMDq6bEJosOjWfnBgptfMP oKnvR2y9cfel1MjJDyxjAR4JXuTgjFzWIzQ9JaoBwLsLNoV1Qe7Bu6DSfJ2dK6KP5KdU=; 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 v4 05/11] viridian: use hypercall_vpmask in hvcall_ipi() Date: Wed, 2 Dec 2020 09:22:01 +0000 Message-Id: <20201202092205.906-6-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-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é" v3: - Couple of extra 'const' qualifiers v2: - Drop the 'vp' loop now that vpmask_set() will do it internally --- xen/arch/x86/hvm/viridian/viridian.c | 44 +++++++++++++++++++++------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index cfd87504052f..fb38210e2cc7 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -551,6 +551,26 @@ static bool vpmask_test(const struct hypercall_vpmask *vpmask, return test_bit(vp, vpmask->mask); } +static unsigned int vpmask_first(const struct hypercall_vpmask *vpmask) +{ + return find_first_bit(vpmask->mask, HVM_MAX_VCPUS); +} + +static unsigned int vpmask_next(const 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 +651,21 @@ static int hvcall_flush(const 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(const union hypercall_input *input, union hypercall_output *output, paddr_t input_params_gpa, paddr_t 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 +704,10 @@ static int hvcall_ipi(const 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; } From patchwork Wed Dec 2 09:22:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945375 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.7 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 0ADB4C83017 for ; Wed, 2 Dec 2020 09:22:31 +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 8D17B20872 for ; Wed, 2 Dec 2020 09:22:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D17B20872 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.42508.76501 (Exim 4.92) (envelope-from ) id 1kkOL1-00036f-9M; Wed, 02 Dec 2020 09:22:15 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42508.76501; Wed, 02 Dec 2020 09:22:15 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL1-00036G-0H; Wed, 02 Dec 2020 09:22:15 +0000 Received: by outflank-mailman (input) for mailman id 42508; Wed, 02 Dec 2020 09:22:14 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL0-00034p-EE for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:14 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL0-0004qb-3K; Wed, 02 Dec 2020 09:22:14 +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 1kkOKz-0006CD-RH; Wed, 02 Dec 2020 09:22:14 +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" 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=rXcPbRQWkmJ068idR05ATB7vjB/FmCOYwLBsOKxDDNY=; b=U6+Q7VyP145vZC50t7PgjeJL4f xXg1gCbM/FM3sePTVyf0mt0YFA8Di+NSZ6sO4nPT3z42JSdIDVT0PZtTecoiEle0HHRtq8+wQNsJl oTGwIWbvzEKNIQKYn67DFT+ZJztKJAaS5jrgW4VUIKQXnwxrfe1VgsM2Ft1+QTRXbb1Q=; From: Paul Durrant To: xen-devel@lists.xenproject.org Cc: Paul Durrant , Jan Beulich , Wei Liu , Andrew Cooper , =?utf-8?q?Roger_Pau_Monn=C3=A9?= Subject: [PATCH v4 06/11] viridian: use softirq batching in hvcall_ipi() Date: Wed, 2 Dec 2020 09:22:02 +0000 Message-Id: <20201202092205.906-7-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant vlapic_ipi() uses a softirq batching mechanism to improve the efficiency of sending a IPIs to large number of processors. This patch modifies send_ipi() (the worker function called by hvcall_ipi()) to also make use of the mechanism when there multiple bits set the hypercall_vpmask. Signed-off-by: Paul Durrant Reviewed-by: Jan Beulich --- Cc: Wei Liu Cc: Andrew Cooper Cc: "Roger Pau Monné" v2: - Don't add the 'nr' field to struct hypercall_vpmask and use bitmap_weight() instead --- xen/arch/x86/hvm/viridian/viridian.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index fb38210e2cc7..47f15717bcd3 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -571,6 +572,11 @@ static unsigned int vpmask_next(const struct hypercall_vpmask *vpmask, (vp) < HVM_MAX_VCPUS; \ (vp) = vpmask_next(vpmask, vp) ) +static unsigned int vpmask_nr(const struct hypercall_vpmask *vpmask) +{ + return bitmap_weight(vpmask->mask, HVM_MAX_VCPUS); +} + /* * Windows should not issue the hypercalls requiring this callback in the * case where vcpu_id would exceed the size of the mask. @@ -654,10 +660,17 @@ static int hvcall_flush(const union hypercall_input *input, static void send_ipi(struct hypercall_vpmask *vpmask, uint8_t vector) { struct domain *currd = current->domain; + unsigned int nr = vpmask_nr(vpmask); unsigned int vp; + if ( nr > 1 ) + cpu_raise_softirq_batch_begin(); + for_each_vp ( vpmask, vp ) vlapic_set_irq(vcpu_vlapic(currd->vcpu[vp]), vector, 0); + + if ( nr > 1 ) + cpu_raise_softirq_batch_finish(); } static int hvcall_ipi(const union hypercall_input *input, From patchwork Wed Dec 2 09:22:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945371 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.7 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 27F58C64E8A for ; Wed, 2 Dec 2020 09:22:28 +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 ADEC220C56 for ; Wed, 2 Dec 2020 09:22:27 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org ADEC220C56 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.42509.76521 (Exim 4.92) (envelope-from ) id 1kkOL3-0003CI-OO; Wed, 02 Dec 2020 09:22:17 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42509.76521; Wed, 02 Dec 2020 09:22:17 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL3-0003C4-HO; Wed, 02 Dec 2020 09:22:17 +0000 Received: by outflank-mailman (input) for mailman id 42509; Wed, 02 Dec 2020 09:22:15 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL1-00037J-EE for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:15 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL1-0004qi-7x; Wed, 02 Dec 2020 09:22:15 +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 1kkOL0-0006CD-WC; Wed, 02 Dec 2020 09:22:15 +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" 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=2McqarQ48ceH9xo3HrtqQ787rnJw7CqOtU4aFIIyXmY=; b=VrfCTBgvonhJEYdohms63KyNVG O6YoeftfM3WaIJ9RY2iXH+dIoSfaMa6UjrpggzFVMQfAVuMbjvlKDNMjudxN7N7wrxlGbIDiMU3sK GxvLSWdYiNOD1H1cLJjK4pxKJUWE7moBSq3jQfKTjDg1BX3GpULQFwFmFk5T3Qd9iNw0=; 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 v4 07/11] viridian: add ExProcessorMasks variants of the flush hypercalls Date: Wed, 2 Dec 2020 09:22:03 +0000 Message-Id: <20201202092205.906-8-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant The Microsoft Hypervisor TLFS specifies variants of the already implemented HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE/LIST hypercalls that take a 'Virtual Processor Set' as an argument rather than a simple 64-bit mask. This patch adds a new hvcall_flush_ex() function to implement these (HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE/LIST_EX) hypercalls. This makes use of new helper functions, hv_vpset_nr_banks() and hv_vpset_to_vpmask(), to determine the size of the Virtual Processor Set (so it can be copied from guest memory) and parse it into hypercall_vpmask (respectively). NOTE: A guest should not yet issue these hypercalls as 'ExProcessorMasks' support needs to be advertised via CPUID. This will be done in a subsequent patch. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v3: - Adjust one of the helper macros - A few more consts and type tweaks - Adjust prototype of new function v2: - Add helper macros to define mask and struct sizes - Use a union to determine the size of 'hypercall_vpset' - Use hweight64() in hv_vpset_nr_banks() - Sanity check size before hvm_copy_from_guest_phys() --- xen/arch/x86/hvm/viridian/viridian.c | 141 +++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 47f15717bcd3..fceca760b41d 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -577,6 +577,69 @@ static unsigned int vpmask_nr(const struct hypercall_vpmask *vpmask) return bitmap_weight(vpmask->mask, HVM_MAX_VCPUS); } +#define HV_VPSET_BANK_SIZE \ + sizeof_field(struct hv_vpset, bank_contents[0]) + +#define HV_VPSET_SIZE(banks) \ + (offsetof(struct hv_vpset, bank_contents) + \ + ((banks) * HV_VPSET_BANK_SIZE)) + +#define HV_VPSET_MAX_BANKS \ + (sizeof_field(struct hv_vpset, valid_bank_mask) * 8) + +union hypercall_vpset { + struct hv_vpset set; + uint8_t pad[HV_VPSET_SIZE(HV_VPSET_MAX_BANKS)]; +}; + +static DEFINE_PER_CPU(union hypercall_vpset, hypercall_vpset); + +static unsigned int hv_vpset_nr_banks(struct hv_vpset *vpset) +{ + return hweight64(vpset->valid_bank_mask); +} + +static uint16_t hv_vpset_to_vpmask(const struct hv_vpset *set, + struct hypercall_vpmask *vpmask) +{ +#define NR_VPS_PER_BANK (HV_VPSET_BANK_SIZE * 8) + + switch ( set->format ) + { + case HV_GENERIC_SET_ALL: + vpmask_fill(vpmask); + return 0; + + case HV_GENERIC_SET_SPARSE_4K: + { + uint64_t bank_mask; + unsigned int vp, bank = 0; + + vpmask_empty(vpmask); + for ( vp = 0, bank_mask = set->valid_bank_mask; + bank_mask; + vp += NR_VPS_PER_BANK, bank_mask >>= 1 ) + { + if ( bank_mask & 1 ) + { + uint64_t mask = set->bank_contents[bank]; + + vpmask_set(vpmask, vp, mask); + bank++; + } + } + return 0; + } + + default: + break; + } + + return -EINVAL; + +#undef NR_VPS_PER_BANK +} + /* * Windows should not issue the hypercalls requiring this callback in the * case where vcpu_id would exceed the size of the mask. @@ -657,6 +720,78 @@ static int hvcall_flush(const union hypercall_input *input, return 0; } +static int hvcall_flush_ex(const union hypercall_input *input, + union hypercall_output *output, + 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; + struct hv_vpset set; + } input_params; + + /* These hypercalls should never use the fast-call convention. */ + if ( input->fast ) + return -EINVAL; + + /* Get input parameters. */ + if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, + sizeof(input_params)) != HVMTRANS_okay ) + return -EINVAL; + + if ( input_params.flags & HV_FLUSH_ALL_PROCESSORS ) + vpmask_fill(vpmask); + else + { + union hypercall_vpset *vpset = &this_cpu(hypercall_vpset); + struct hv_vpset *set = &vpset->set; + size_t size; + int rc; + + *set = input_params.set; + if ( set->format == HV_GENERIC_SET_SPARSE_4K ) + { + unsigned long offset = offsetof(typeof(input_params), + set.bank_contents); + + size = sizeof(*set->bank_contents) * hv_vpset_nr_banks(set); + + if ( offsetof(typeof(*vpset), set.bank_contents[0]) + size > + sizeof(*vpset) ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + + if ( hvm_copy_from_guest_phys(&set->bank_contents[0], + input_params_gpa + offset, + size) != HVMTRANS_okay) + return -EINVAL; + + size += sizeof(*set); + } + else + size = sizeof(*set); + + rc = hv_vpset_to_vpmask(set, vpmask); + if ( rc ) + return rc; + } + + /* + * A false return means that another vcpu is currently trying + * a similar operation, so back off. + */ + if ( !paging_flush_tlb(need_flush, vpmask) ) + return -ERESTART; + + output->rep_complete = input->rep_count; + + return 0; +} + static void send_ipi(struct hypercall_vpmask *vpmask, uint8_t vector) { struct domain *currd = current->domain; @@ -770,6 +905,12 @@ int viridian_hypercall(struct cpu_user_regs *regs) output_params_gpa); break; + case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX: + case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX: + rc = hvcall_flush_ex(&input, &output, input_params_gpa, + output_params_gpa); + break; + case HVCALL_SEND_IPI: rc = hvcall_ipi(&input, &output, input_params_gpa, output_params_gpa); From patchwork Wed Dec 2 09:22:04 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945379 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.7 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 3B167C83013 for ; Wed, 2 Dec 2020 09:22:31 +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 CAE4F20C56 for ; Wed, 2 Dec 2020 09:22:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CAE4F20C56 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.42511.76532 (Exim 4.92) (envelope-from ) id 1kkOL4-0003Eb-Tb; Wed, 02 Dec 2020 09:22:18 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42511.76532; Wed, 02 Dec 2020 09:22:18 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL4-0003Dc-40; Wed, 02 Dec 2020 09:22:18 +0000 Received: by outflank-mailman (input) for mailman id 42511; Wed, 02 Dec 2020 09:22:16 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL2-0003AT-Js for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:16 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL2-0004qv-Cc; Wed, 02 Dec 2020 09:22:16 +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 1kkOL2-0006CD-4h; Wed, 02 Dec 2020 09:22:16 +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" 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=Gt2Gm0WXXUEpvKgVkyBf36jhM5Cv2I4ub9rwEjAgTo0=; b=25jlMVPl80HFOvfhQj59s90ZWD s0F2bzsjBcDmkAAxhiL5Rn1/OGKLpVNbhwwM+k/ULKIvHVdybUeeiQOStJt0KpuHZPN+gdACpYQ6l l8w7fqvAGwLjGJe6GRxksplffffO7vrkihWOxXQZFWNddfiZgcRR4OQbjWZ7l5IgymMk=; 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 v4 08/11] viridian: add ExProcessorMasks variant of the IPI hypercall Date: Wed, 2 Dec 2020 09:22:04 +0000 Message-Id: <20201202092205.906-9-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant A previous patch introduced variants of the flush hypercalls that take a 'Virtual Processor Set' as an argument rather than a simple 64-bit mask. This patch introduces a similar variant of the HVCALL_SEND_IPI hypercall (HVCALL_SEND_IPI_EX). NOTE: As with HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE/LIST_EX, a guest should not yet issue the HVCALL_SEND_IPI_EX hypercall as support for 'ExProcessorMasks' is not yet advertised via CPUID. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v3: - Adjust prototype of new function v2: - Sanity check size before hvm_copy_from_guest_phys() --- xen/arch/x86/hvm/viridian/viridian.c | 74 ++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index fceca760b41d..9aa8e6c2572c 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -860,6 +860,75 @@ static int hvcall_ipi(const union hypercall_input *input, return 0; } +static int hvcall_ipi_ex(const union hypercall_input *input, + union hypercall_output *output, + paddr_t input_params_gpa, + paddr_t output_params_gpa) +{ + struct hypercall_vpmask *vpmask = &this_cpu(hypercall_vpmask); + struct { + uint32_t vector; + uint8_t target_vtl; + uint8_t reserved_zero[3]; + struct hv_vpset set; + } input_params; + union hypercall_vpset *vpset = &this_cpu(hypercall_vpset); + struct hv_vpset *set = &vpset->set; + size_t size; + int rc; + + /* These hypercalls should never use the fast-call convention. */ + if ( input->fast ) + return -EINVAL; + + /* Get input parameters. */ + if ( hvm_copy_from_guest_phys(&input_params, input_params_gpa, + sizeof(input_params)) != HVMTRANS_okay ) + return -EINVAL; + + if ( input_params.target_vtl || + input_params.reserved_zero[0] || + input_params.reserved_zero[1] || + input_params.reserved_zero[2] ) + return HV_STATUS_INVALID_PARAMETER; + + if ( input_params.vector < 0x10 || input_params.vector > 0xff ) + return HV_STATUS_INVALID_PARAMETER; + + *set = input_params.set; + if ( set->format == HV_GENERIC_SET_SPARSE_4K ) + { + unsigned long offset = offsetof(typeof(input_params), + set.bank_contents); + + size = sizeof(*set->bank_contents) * hv_vpset_nr_banks(set); + + if ( offsetof(typeof(*vpset), set.bank_contents[0]) + size > + sizeof(*vpset) ) + { + ASSERT_UNREACHABLE(); + return -EINVAL; + } + + if ( hvm_copy_from_guest_phys(&set->bank_contents, + input_params_gpa + offset, + size) != HVMTRANS_okay) + return -EINVAL; + + size += sizeof(*set); + } + else + size = sizeof(*set); + + rc = hv_vpset_to_vpmask(set, vpmask); + if ( rc ) + return rc; + + send_ipi(vpmask, input_params.vector); + + return 0; +} + int viridian_hypercall(struct cpu_user_regs *regs) { struct vcpu *curr = current; @@ -916,6 +985,11 @@ int viridian_hypercall(struct cpu_user_regs *regs) output_params_gpa); break; + case HVCALL_SEND_IPI_EX: + rc = hvcall_ipi_ex(&input, &output, input_params_gpa, + output_params_gpa); + break; + default: gprintk(XENLOG_WARNING, "unimplemented hypercall %04x\n", input.call_code); From patchwork Wed Dec 2 09:22:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paul Durrant X-Patchwork-Id: 11945373 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.7 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 79BEFC71155 for ; Wed, 2 Dec 2020 09:22: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 0B6A420872 for ; Wed, 2 Dec 2020 09:22:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0B6A420872 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.42512.76549 (Exim 4.92) (envelope-from ) id 1kkOL6-0003KL-Mj; Wed, 02 Dec 2020 09:22:20 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 42512.76549; Wed, 02 Dec 2020 09:22:20 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL6-0003Jv-Eq; Wed, 02 Dec 2020 09:22:20 +0000 Received: by outflank-mailman (input) for mailman id 42512; Wed, 02 Dec 2020 09:22:18 +0000 Received: from mail.xenproject.org ([104.130.215.37]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL3-0003Cx-UN for xen-devel@lists.xenproject.org; Wed, 02 Dec 2020 09:22:17 +0000 Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kkOL3-0004r2-Hd; Wed, 02 Dec 2020 09:22:17 +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 1kkOL3-0006CD-9c; Wed, 02 Dec 2020 09:22:17 +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" 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=Pgl96KUiTKNG1FAmFTz8k9V801W3LGUJk8d0gWn7PzM=; b=LCEq8Mx+1Piq1b7P3sadP0P4Bn GOygdLUclZW9Avp+RpKcDQrX2wk/DMaktHc7lagUQrYjglb8tRajC8C95hkBV5OpxSJlEWVo23Kp+ OAdzhp4uBMFQ9dRtGwO+WakzP2BJKv2pgs+DzPOwmBAKdFyf49tJJyUC9+Q6D0Wisr2I=; 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 v4 09/11] viridian: log initial invocation of each type of hypercall Date: Wed, 2 Dec 2020 09:22:05 +0000 Message-Id: <20201202092205.906-10-paul@xen.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20201202092205.906-1-paul@xen.org> References: <20201202092205.906-1-paul@xen.org> MIME-Version: 1.0 From: Paul Durrant To make is simpler to observe which viridian hypercalls are issued by a particular Windows guest, this patch adds a per-domain mask to track them. Each type of hypercall causes a different bit to be set in the mask and when the bit transitions from clear to set, a log line is emitted showing the name of the hypercall and the domain that issued it. Signed-off-by: Paul Durrant --- Cc: Wei Liu Cc: Jan Beulich Cc: Andrew Cooper Cc: "Roger Pau Monné" v2: - Use DECLARE_BITMAP() for 'hypercall_flags' - Use an enum for _HCALL_* values --- xen/arch/x86/hvm/viridian/viridian.c | 21 +++++++++++++++++++++ xen/include/asm-x86/hvm/viridian.h | 10 ++++++++++ 2 files changed, 31 insertions(+) diff --git a/xen/arch/x86/hvm/viridian/viridian.c b/xen/arch/x86/hvm/viridian/viridian.c index 9aa8e6c2572c..95314c1f7f6c 100644 --- a/xen/arch/x86/hvm/viridian/viridian.c +++ b/xen/arch/x86/hvm/viridian/viridian.c @@ -933,6 +933,7 @@ int viridian_hypercall(struct cpu_user_regs *regs) { struct vcpu *curr = current; struct domain *currd = curr->domain; + struct viridian_domain *vd = currd->arch.hvm.viridian; int mode = hvm_guest_x86_mode(curr); unsigned long input_params_gpa, output_params_gpa; int rc = 0; @@ -962,6 +963,10 @@ int viridian_hypercall(struct cpu_user_regs *regs) switch ( input.call_code ) { case HVCALL_NOTIFY_LONG_SPIN_WAIT: + if ( !test_and_set_bit(_HCALL_spin_wait, vd->hypercall_flags) ) + printk(XENLOG_G_INFO "d%d: VIRIDIAN HVCALL_NOTIFY_LONG_SPIN_WAIT\n", + currd->domain_id); + /* * See section 14.5.1 of the specification. */ @@ -970,22 +975,38 @@ int viridian_hypercall(struct cpu_user_regs *regs) case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST: + if ( !test_and_set_bit(_HCALL_flush, vd->hypercall_flags) ) + printk(XENLOG_G_INFO "%pd: VIRIDIAN HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE/LIST\n", + currd); + rc = hvcall_flush(&input, &output, input_params_gpa, output_params_gpa); break; case HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX: case HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST_EX: + if ( !test_and_set_bit(_HCALL_flush_ex, vd->hypercall_flags) ) + printk(XENLOG_G_INFO "%pd: VIRIDIAN HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE/LIST_EX\n", + currd); + rc = hvcall_flush_ex(&input, &output, input_params_gpa, output_params_gpa); break; case HVCALL_SEND_IPI: + if ( !test_and_set_bit(_HCALL_ipi, vd->hypercall_flags) ) + printk(XENLOG_G_INFO "%pd: VIRIDIAN HVCALL_SEND_IPI\n", + currd); + rc = hvcall_ipi(&input, &output, input_params_gpa, output_params_gpa); break; case HVCALL_SEND_IPI_EX: + if ( !test_and_set_bit(_HCALL_ipi_ex, vd->hypercall_flags) ) + printk(XENLOG_G_INFO "%pd: VIRIDIAN HVCALL_SEND_IPI_EX\n", + currd); + rc = hvcall_ipi_ex(&input, &output, input_params_gpa, output_params_gpa); break; diff --git a/xen/include/asm-x86/hvm/viridian.h b/xen/include/asm-x86/hvm/viridian.h index cbf77d9c760b..4c8ff6e80b6f 100644 --- a/xen/include/asm-x86/hvm/viridian.h +++ b/xen/include/asm-x86/hvm/viridian.h @@ -55,10 +55,20 @@ struct viridian_time_ref_count int64_t off; }; +enum { + _HCALL_spin_wait, + _HCALL_flush, + _HCALL_flush_ex, + _HCALL_ipi, + _HCALL_ipi_ex, + _HCALL_nr /* must be last */ +}; + struct viridian_domain { union hv_guest_os_id guest_os_id; union hv_vp_assist_page_msr hypercall_gpa; + DECLARE_BITMAP(hypercall_flags, _HCALL_nr); struct viridian_time_ref_count time_ref_count; struct viridian_page reference_tsc; };