Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp2591587rwr; Fri, 28 Apr 2023 12:35:21 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6elWCH2xCDsKiPipFkMLjitV0GMB0FIfpfgR3zYQ+CD/jaoQVO/97tvsUu1wmezhO2Y/Fg X-Received: by 2002:a17:90b:212:b0:247:9450:eb6d with SMTP id fy18-20020a17090b021200b002479450eb6dmr5763631pjb.49.1682710521550; Fri, 28 Apr 2023 12:35:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682710521; cv=none; d=google.com; s=arc-20160816; b=iPfzVS67F5YPkeWoOk2ygyOTCpxsHDuACX1rI9JVz2E8UYnTO9ZUtMtH7gbqhMqw2k aP6eF7v16YA9QHcKrZWCJU3TJ7tYh8t2D0WtRxk2n7Dxsi6xiv8dZtCRjOEcq8fxMPli NcXn1UzPHuf6LbgZN+zqzZN4QpkTPjQUpVY2drljemNNx3VxuSgDe5a/FESQzT9+yVZD o5XDzm66c4VfIPyMlvG2V4QeW/Vm/rL/BDfXUZtCpcRBC5fz5foAv/WegCdNMhglea2A qWRLLWENs247g8RbjbBOLvELSOkXMFoO0s8Lzvp8d25vF7i1H/6v1HRAbc9ZVuTMGERk pRXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=V/c8uRbwwP0oktN8Q6FJxvMxpBfclwld1hCDkRXWUfs=; b=jkj1FEVSttm1khfk834Xfjyhh83Frgd87gUNld7ROHMSEcErrPCV1j/OKOc84xvVkO Hp5wya6/ddolyLLGmPrk6F8hE30Mw43+RHCdOTJwHX14a2M6lezE6Uhfl5R1pTTGQUFR x371lJEy2juGmmHxmFP1rkkJkoC5JMRxTrjsUJGmp9KSZ5Sa+X1VJYKSL8/n+2LEjZKa Rj6SU4ztsyAAP4smHSt1l74oPvuIT1W3NDNcIcsnUivTHD2DBUWoLfXm7/t79HqthYlG amVwwPlyKP/UEBNHpOtHOEGYfFZhku4oHwQQJhH2ogfIkXTasTDw48yEjXGpJLS3svES SpWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=R1bgskUA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 23-20020a17090a0c1700b002477fad79d5si23559609pjs.63.2023.04.28.12.35.09; Fri, 28 Apr 2023 12:35:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=R1bgskUA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346468AbjD1TRj (ORCPT + 99 others); Fri, 28 Apr 2023 15:17:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229862AbjD1TRh (ORCPT ); Fri, 28 Apr 2023 15:17:37 -0400 Received: from mail-pg1-x549.google.com (mail-pg1-x549.google.com [IPv6:2607:f8b0:4864:20::549]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D28F92134 for ; Fri, 28 Apr 2023 12:17:35 -0700 (PDT) Received: by mail-pg1-x549.google.com with SMTP id 41be03b00d2f7-52503bfeb07so74646a12.3 for ; Fri, 28 Apr 2023 12:17:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1682709455; x=1685301455; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=V/c8uRbwwP0oktN8Q6FJxvMxpBfclwld1hCDkRXWUfs=; b=R1bgskUAKm7pZ0pTjkgtdtw25rXseg0tc16RNncwq38lXHWBUxwGm101B8qPs3Y3Y/ jg6fBoFWV2Y1bLYNb8WU6EpqqAjEZ7GPBPMH8QoJPWx5PHrETQ57XPRF+EZ0HTmDNOu+ brvIzLIN0BVmCb9z3c3V0TJ2ErjKMf88mtnhxUpFb8jUeD2wqRa4PKbl+6H8N4EYzntG MCQA247alzQLcmxsZMaTpCUXCVSOVmShzpYKwsT5PHawZXc+HaZHKc/vSOXoX0ldOEBD z/FR6C3rz9y5rFI7QoDsrnkpQrba+mqwBtFmWkRlrGqAoYmKMy90yNldPu3yGAcT/YNs Vd8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682709455; x=1685301455; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=V/c8uRbwwP0oktN8Q6FJxvMxpBfclwld1hCDkRXWUfs=; b=OT0gmmsZnH87sPcdoWblCW6akuuzsOM27fQ2UoR89MHEWt3084dw9VI/phjJ1wGgdn CED9U/rX4+W1SnVAOudOPpF7nG2jIwTQBGkivxCwrEktEu51ljhJ0q3+6rXm2rrywfLs KIoWm6ecSwQMsQvuxmRls6PclppRgAaKCNlg5hlo44OLN/DUcTg52Ka+SJBP9R/UBlfM HAjgiiOq3A17KNFK6qs20v4gWIEwYomJLk7bqecrPHd2x6tNPsMnrptYNSvgiVWIZ6/6 uBucGr7LCVVAy2CxwnPzc8i3MBw9APMQfNxnY63ld3poSgeZNLgTDiAmeO5zz1NYfXkS C38A== X-Gm-Message-State: AC+VfDy/zdaHmHxK/zqxFVLQn1K5dPOmvDSl7m//WI5RQtc5+d1faEru rY2UGOliywg/inTEQRhnAs2rfy8SMQrC X-Received: from afranji.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:47f1]) (user=afranji job=sendgmr) by 2002:a63:8a4b:0:b0:51b:70c9:c1e0 with SMTP id y72-20020a638a4b000000b0051b70c9c1e0mr1562202pgd.12.1682709455253; Fri, 28 Apr 2023 12:17:35 -0700 (PDT) Date: Fri, 28 Apr 2023 19:17:33 +0000 In-Reply-To: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.40.1.495.gc816e09b53d-goog Message-ID: <20230428191733.3428555-1-afranji@google.com> Subject: Re: [PATCH v13 098/113] KVM: TDX: Handle TDX PV map_gpa hypercall From: Ryan Afranji To: isaku.yamahata@intel.com Cc: dmatlack@google.com, erdemaktas@google.com, isaku.yamahata@gmail.com, kai.huang@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, sagis@google.com, seanjc@google.com, zhi.wang.linux@gmail.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org +static int tdx_map_gpa(struct kvm_vcpu *vcpu) +{ + struct kvm *kvm = vcpu->kvm; + gpa_t gpa = tdvmcall_a0_read(vcpu); + gpa_t size = tdvmcall_a1_read(vcpu); + gpa_t end = gpa + size; + + if (!IS_ALIGNED(gpa, PAGE_SIZE) || !IS_ALIGNED(size, PAGE_SIZE) || + end < gpa || + end > kvm_gfn_shared_mask(kvm) << (PAGE_SHIFT + 1) || + kvm_is_private_gpa(kvm, gpa) != kvm_is_private_gpa(kvm, end)) { + tdvmcall_set_return_code(vcpu, TDG_VP_VMCALL_INVALID_OPERAND); According to table 3-6 of the GHCI spec, TDG.VP.VMCALL_ALIGN_ERROR should be returned if there is an alignment error for the size or start GPA. Right now, TDG_VP_VMCALL_INVALID_OPERAND is being returned instead. Can this be updated? + return 1; + } + + return tdx_vp_vmcall_to_user(vcpu); +} +