Received: by 2002:a89:288:0:b0:1f7:eeee:6653 with SMTP id j8csp89688lqh; Mon, 6 May 2024 12:10:58 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWeOM3QBIZlrZ7yfLqNJopqsMB8eXKWc19HzSmapGnRLI4FgN7g3iuq2qysgeZLvIjJmQf9+5LQTfFXq3kKdirzTar/DuRVpqCaibDfgg== X-Google-Smtp-Source: AGHT+IHJFqed+KTrob4col/8D0qYLNxAXH43c+uMEASwvjkOOb2ffopbNef92MmyyKZZ2K9ci13Y X-Received: by 2002:a05:6a20:3251:b0:1ac:3d3c:c1e7 with SMTP id adf61e73a8af0-1afbdca8a39mr727117637.12.1715022658285; Mon, 06 May 2024 12:10:58 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715022658; cv=pass; d=google.com; s=arc-20160816; b=JZWTISFffYM8uErrXdUTxPBTRePqK3F+tnf8Ea9eea36FG8q6kcDkVZfBGs9RszuLA qBBw3oQamn4zhOlad3dvWabxmacF+8aGMERmGmXg7O7ixx1kQjkvIbQ42B+TN+q6zOUo XmwMn+cNKavdp1FgL/FHKtZE824Wfz1xqjWmHwceClH4fVaDwLo+2BkcauTCweHNHU5E xrzn2wUfKQWBhQYxgnvxNyQKlsW5juKlx9PX2qlXx5urdUxPGVYTpao05Z2xllvG37bd NLqJj9hZj+/clQp9HMj3QeAph0i/D1WlJenjjoALuM1CQHpSQCPznswNrv4nImCWzTb0 E7lw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=vXvOd56hX98lt1BNkZiUNoua2GthUmlz4bM7I7fsoxo=; fh=ZNdrJufTjcVd/tVUPNfjMl/1jhCSlmTlYOuYBehJ/tA=; b=A71R35jsm8bVcbJNtdQOUwQEat47EzvsjhfVeDuhYhvBVWYKJrfzTcDsX9uZCOmfQd NDPVOs0OwcCA06eV5+o5mO/tEMeR5AODFWDilmRJMm+7Fea2gFfUp9uLNqvrGoOv3D57 gziXOA9Ihnx1wY4yev54IAohpmZWgW5bukinQy+PhhdpbCkADER2fpcmy1MXEcsP88OX awxiVhQeWPXl01z0eSd2gq/3p4dmEwu4oMTzg1X5gxu49YCNJbxQDti79ejPoPOnRR1q a5bGxYEmnrDDrJwLZKkGyi1c3vnmdSVJ8iKFbixJKrPdY1z7etTrsO4cyauWmXhVQYv1 wlNg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=I2J6A22s; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-170326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s18-20020a656912000000b0061cd65b4356si7265801pgq.826.2024.05.06.12.10.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 12:10:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-170326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=I2J6A22s; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=intel.com); spf=pass (google.com: domain of linux-kernel+bounces-170326-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-170326-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B880728319A for ; Mon, 6 May 2024 19:10:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BB35C1591F9; Mon, 6 May 2024 19:10:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="I2J6A22s" Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 24DC0158DD5; Mon, 6 May 2024 19:10:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.175.65.19 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715022643; cv=none; b=GWb8+Ioeg3JjO4ghzwdcYZ8tltOMWCGlwSChM7EIUr2ClaUkkQ1mYZqlp7ucvY1tE19IyeSWFCyUDCOqngBv0NJmlJsP5fpo+nuyqLprMJ6YO0W7x3HLAn0EjXifiIcdWurWtL9maTyEZdjS0yRtGhq9rUs7NFk91BU1TlDfNu0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715022643; c=relaxed/simple; bh=kPCSlFZ/lSBt4Pb75v7rCK1VScHWGpdu2/lhZVIUnFM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FM8XiZZd7ItnUPIbOnWYnFNxMtFDadjjWQDkqeTRjArdFqk/rM3RaDdOZ6DjhIZk3PvIpwbJ/lXSA2EtKWeZ6b0/6jYJG6iM9ZiSjJjdyE/bhd0LraO+i5LlkPxH8qkYkK9FHlQL97HoNMUsbSOD32k/1CP4CBWWYL1J/wJu5Pg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=I2J6A22s; arc=none smtp.client-ip=198.175.65.19 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1715022642; x=1746558642; h=date:from:to:cc:subject:message-id:references: mime-version:content-transfer-encoding:in-reply-to; bh=kPCSlFZ/lSBt4Pb75v7rCK1VScHWGpdu2/lhZVIUnFM=; b=I2J6A22sTpl+tEIaT3v4LI904FId8r9SqCLnDqzSyemho0BWhPsGsXkU 0VBo+2ka6wTW+nGDe53Z6UejuRBfQDq9NgLFTLidaLHIznIAEurRI5nv7 ThNDdsifslXeyVW/kyUqSpIB79umdbTmBt7r0Td0nTICcv/P4bYahxyeo xtYAOOnzPu7wXcV3AnxqyLF2T9rG2W/AEKxekKNNhJrLcXC/iJn5K6HNo ekmSkcE+/fZmq9P57uP9Z62AIIpBZ4thwpGbeXJBJZY2R8hC9PzfQQzuB oJ0qTcnl3HfXUVvFvqnJ1cXi+Kutdas86fV2+XWfrQgYjpDZAUpDGV6jL w==; X-CSE-ConnectionGUID: Q15XhlraSuSqpNUnMUgXcA== X-CSE-MsgGUID: P4KfYnaEQ52VF1fSbCU/jw== X-IronPort-AV: E=McAfee;i="6600,9927,11065"; a="10633270" X-IronPort-AV: E=Sophos;i="6.07,259,1708416000"; d="scan'208";a="10633270" Received: from orviesa009.jf.intel.com ([10.64.159.149]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 12:10:41 -0700 X-CSE-ConnectionGUID: cN8StRI6TXKdC5LTZBgCOA== X-CSE-MsgGUID: PMOoDdOgSv+aA3f33moy0A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,259,1708416000"; d="scan'208";a="28351970" Received: from ls.sc.intel.com (HELO localhost) ([172.25.112.31]) by orviesa009-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2024 12:10:41 -0700 Date: Mon, 6 May 2024 12:10:39 -0700 From: Isaku Yamahata To: Binbin Wu Cc: isaku.yamahata@intel.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, isaku.yamahata@gmail.com, Paolo Bonzini , erdemaktas@google.com, Sean Christopherson , Sagi Shahar , Kai Huang , chen.bo@intel.com, hang.yuan@intel.com, tina.zhang@intel.com, Xiaoyao Li , Sean Christopherson , Chao Gao , Reinette Chatre , rick.p.edgecombe@intel.com Subject: Re: [PATCH v19 088/130] KVM: x86: Add a switch_db_regs flag to handle TDX's auto-switched behavior Message-ID: <20240506191039.GE13783@ls.amr.corp.intel.com> References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Mon, May 06, 2024 at 11:30:52AM +0800, Binbin Wu wrote: > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 1b189e86a1f1..fb7597c22f31 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -11013,7 +11013,7 @@ static int vcpu_enter_guest(struct kvm_vcpu *vcpu) > > if (vcpu->arch.guest_fpu.xfd_err) > > wrmsrl(MSR_IA32_XFD_ERR, vcpu->arch.guest_fpu.xfd_err); > > - if (unlikely(vcpu->arch.switch_db_regs)) { > > + if (unlikely(vcpu->arch.switch_db_regs & ~KVM_DEBUGREG_AUTO_SWITCH)) { > > As pointed by Paolo in > https://lore.kernel.org/lkml/ea136ac6-53cf-cdc5-a741-acfb437819b1@redhat.com/ > KVM_DEBUGREG_BP_ENABLED could be set in vcpu->arch.switch_db_regs,  by > userspace > kvm_vcpu_ioctl_x86_set_debugregs()  --> kvm_update_dr7() > > So it should be fixed as: > > -       if (unlikely(vcpu->arch.switch_db_regs)) { > +       if (unlikely(vcpu->arch.switch_db_regs && > +                    !(vcpu->arch.switch_db_regs & > KVM_DEBUGREG_AUTO_SWITCH))) { Yes, that's true. Thanks for catching this. -- Isaku Yamahata