Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp175948lqm; Tue, 30 Apr 2024 17:28:49 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXb6pDds0DlA6sLGkO1zq6rGojLLnqM5PZXEUJ1Ehlppypfn3pnleKyVINInsiM+Red+uBWSpVrMpWhqcPPc4IJWjqvnknC4bQVEZL+qg== X-Google-Smtp-Source: AGHT+IHWikxjmgmGO/O1CDfdY77H+rkOgahhLwmHYMXwNyzasUAP+03FwUi0/G49rP5Ve6Xpg4ct X-Received: by 2002:a17:906:5659:b0:a55:6129:85dd with SMTP id v25-20020a170906565900b00a55612985ddmr806645ejr.55.1714523329635; Tue, 30 Apr 2024 17:28:49 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714523329; cv=pass; d=google.com; s=arc-20160816; b=YRvLYcX3osvEIEdxT7KD3NM5Up08gSuZF55Rs9tnuZd+a+nGbnkbvj8BBsWM9sEsax 18Wzii9okEdRHc2Xg48xxSh5cYj8Jn9g3mryu4GUmOJHwctF2fVICwp/kjQ5O+8tOqsO S0I4c52rDuY1lCVkrqUUpafqv+ffP1I5RuMUVxWMnAqyWohP3wP55wPG44u4aEK9Rh3j 7yTQjQn0PY14bE2PsY1QoMZMC/x1H/N/HZwsOMzAenQLh2JAqYQFRxajAPc9byDyiDCY V18HkOsdIvjNmPUTj5jEnE6uhGoqIC/EavSgh7aZCuC42+OBXoRpav5mC/1rM4LQb2aY UI3Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=ioXgnZIoOxV6Gom6pZgkz9FqddFwrAkScDhYF7eexw0=; fh=j3GB/m7NbW+xI2Q6rSwMt0ZZ5txZtE2iyXMuuS2qupY=; b=jbt3th+t3KSHgQWp925BKBpg5Xa1NaNVzlFb0DOOPIdTRE0RkSUpXjfcBim2qbiiFb 5rGf4UAcyh9hmg0hFX+F3tMjlMF6FHPLfVyMF/jTNfJWlFaQISTYoyvx9+L3AHz0+NNb D4ja8rwgcNcO3HkiUnK8mgUrQ7FnN/CWsWQpxjk30YwWynCurh/bJKdWC5vFSu+l65Rn lxeUCfCT3CLXlGqnjQHeWzHgvtzKR6OWnHTVam0z2f9PBdAPgQFw3ORKjYyjAjJwlAbK AmjkCNrt6rdHnHcL//5ovRcoijjAx4DI10H4MHhvVK7TATrisNOZeN4rRwHdrKUtJ6v7 RGdw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="jt/Q3cVC"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-164833-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164833-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v15-20020a50d58f000000b005720db30947si11203552edi.586.2024.04.30.17.28.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 17:28:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-164833-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="jt/Q3cVC"; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-164833-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-164833-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 609641F23086 for ; Wed, 1 May 2024 00:28:49 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F203153A9; Wed, 1 May 2024 00:28:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jt/Q3cVC" Received: from out-185.mta1.migadu.com (out-185.mta1.migadu.com [95.215.58.185]) (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 6AD1033EE for ; Wed, 1 May 2024 00:28:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.185 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714523307; cv=none; b=N55xIBNRwLodLBL/wKQsDLy2x11L3w659oV5ZnxWJSXVMeXj4MT4QF6GzzB1dLS1pN2Bv9zjeIIPh5RnTTBK4/kXjlgGR92Gt9XQYyUUldRdOd9hsDgKQWx+VFbfjWWbFApTUOuNFWuzILf4E2hYeuPQfhGDXYlvbthehng7EiU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714523307; c=relaxed/simple; bh=DpFUUK9f7pvRbaNn+oUsZkhipSX9ZbK/PMBvjjKew0A=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kQ5C6AQqiaOzN+XDqQu/FjePw4vriUzJnx5mz7fLpJXYELYdAOfb5UjECNzuulsESXgyswy4w/GbbrQgzkD1vuQIoedtpTiVO2D95P4pYvcOmoud6Fij0TKheslJhtvG6Q3UpPRa3Bua7fZednZiDt49Ng0OdO1+MbrHDCT9ehU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jt/Q3cVC; arc=none smtp.client-ip=95.215.58.185 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Wed, 1 May 2024 00:28:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714523303; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=ioXgnZIoOxV6Gom6pZgkz9FqddFwrAkScDhYF7eexw0=; b=jt/Q3cVCB5txoE/zQITpY+KTWb0keYgIpc0qkzhVQFsJAZZR5RjRVVdyLf1AD37xVVVKy5 AjuiDAvL2nLBEHIqEzLFqT7OazbzMr6NRwDmnhYgDnVnteqZKpKfa3eZfPYr7Wncyk+0Tk iJCFdMrcVNqaWoqklmPV1Wqci3CPJlw= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Sean Christopherson Cc: Marc Zyngier , Tianrui Zhao , Bibo Mao , Huacai Chen , Michael Ellerman , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, loongarch@lists.linux.dev, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/4] KVM: Fold kvm_arch_sched_in() into kvm_arch_vcpu_load() Message-ID: References: <20240430193157.419425-1-seanjc@google.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240430193157.419425-1-seanjc@google.com> X-Migadu-Flow: FLOW_OUT On Tue, Apr 30, 2024 at 12:31:53PM -0700, Sean Christopherson wrote: > Drop kvm_arch_sched_in() and instead pass a @sched_in boolean to > kvm_arch_vcpu_load(). > > While fiddling with an idea for optimizing state management on AMD CPUs, > I wanted to skip re-saving certain host state when a vCPU is scheduled back > in, as the state (theoretically) shouldn't change for the task while it's > scheduled out. Actually doing that was annoying and unnecessarily brittle > due to having a separate API for the kvm_sched_in() case (the state save > needed to be in kvm_arch_vcpu_load() for the common path). > > E.g. I could have set a "temporary"-ish flag somewhere in kvm_vcpu, but (a) > that's gross and (b) it would rely on the arbitrary ordering between > sched_in() and vcpu_load() staying the same. Another option would be to change the rules around kvm_arch_sched_in() where the callee is expected to load the vCPU context. The default implementation could just call kvm_arch_vcpu_load() directly and the x86 implementation can order things the way it wants before kvm_arch_vcpu_load(). I say this because ... > The only real downside I see is that arm64 and riscv end up having to pass > "false" for their direct usage of kvm_arch_vcpu_load(), and passing boolean > literals isn't ideal. But that can be solved by adding an inner helper that > omits the @sched_in param (I almost added a patch to do that, but I couldn't > convince myself it was necessary). Needing to pass @sched_in for other usage of kvm_arch_vcpu_load() hurts readability, especially when no other architecture besides x86 cares about it. -- Thanks, Oliver